Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(listener): return if there is no arguments #6

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@
[![prettier][prettier-badge]][prettier]
[![license][license-badge]][license]

## Installation

https://github.com/apps/polls

## Usage

1. Configure the GitHub App: [github.com/apps/polls](https://github.com/apps/polls)
2. Add command to issue:

```md
/polls Option1 'Option 2' "Option 3"

# Automatically replace with the following markdown =>
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Option1)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Option1/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Opntio%202)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Opntio%202/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Option%203)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXY635WEJEYKJV0BZ9WFPJVS/Option%203/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option1)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option1/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option%202)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option%202/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option%203)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BXZMATAZ5BXF8RVRAMRSSANA/Option%203/vote)
```

| **Screenshot** | **Demo** |
| **Screenshot** | [![](./docs/screenshot.png)](https://github.com/evenchange4/gh-polls-bot/issues/2) |
| -------------- | -------- |
| ![](./docs/screenshot.png) | ![](./docs/demo.gif) |
| **Demo** | ![](./docs/demo.gif) |

## Developer Guide

Expand All @@ -43,6 +42,8 @@ https://github.com/apps/polls
- Create a `.env` file from `.env.example`.
- Download the `private-key.pem` from GitHub and move it to your project’s directory.

> Note: Please follow the [Developing an App](https://probot.github.io/docs/development/) section of Probot documents.

### Requirements

- node >= 9.0.0
Expand All @@ -69,7 +70,7 @@ $ yarn run flow

Any git commits push to master branch.

> PRIVATE_KEY pem workaround: [first-timers-bot #89](https://github.com/hoodiehq/first-timers-bot/pull/89)
> Note: PRIVATE_KEY pem workaround: [first-timers-bot #89](https://github.com/hoodiehq/first-timers-bot/pull/89)

### Technology Stacks

Expand Down
Binary file modified docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
"engines": {
"node": ">=9.0.0"
},
"jest": {
"testEnvironment": "node",
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!src/**/*.test.{js,jsx}"
],
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/coverage/",
"<rootDir>/flow-typed/"
]
},
"prettier": {
"trailingComma": "all",
"singleQuote": true
Expand Down
52 changes: 51 additions & 1 deletion src/__tests__/listener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ it('should handle addPollListener', async () => {
},
},
github: mockGitHubAPI,
// GitHub API
issue: data => data,
};
await addPollListener(mockContext);
Expand All @@ -35,3 +34,54 @@ it('should handle addPollListener', async () => {
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/3)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/3/vote)`,
});
});

it('should not addLabels if there is one', async () => {
const mockGitHubAPI = {
issues: {
addLabels: jest.fn(),
edit: jest.fn(),
},
};
const mockContext = {
payload: {
issue: {
body: 'H1H3\n/polls 1 2 3',
labels: ['Polls'],
},
},
github: mockGitHubAPI,
issue: data => data,
};
await addPollListener(mockContext);

expect(mockGitHubAPI.issues.addLabels).not.toHaveBeenCalled();
expect(mockGitHubAPI.issues.edit).toHaveBeenCalledWith({
body: `H1H3
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/1)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/1/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/2)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/2/vote)
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/3)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/3/vote)`,
});
});

it('should handle commands without any arguments', async () => {
const mockGitHubAPI = {
issues: {
addLabels: jest.fn(),
edit: jest.fn(),
},
};
const mockContext = {
payload: {
issue: {
body: 'H1H3\n/polls',
labels: ['Polls'],
},
},
github: mockGitHubAPI,
issue: data => data,
};
await addPollListener(mockContext);

expect(mockGitHubAPI.issues.addLabels).not.toHaveBeenCalled();
expect(mockGitHubAPI.issues.edit).not.toHaveBeenCalled();
});
3 changes: 3 additions & 0 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const { LABEL } = require('./utils/config');
const addPollListener = async (context /* : any */) => {
const { body, labels } = context.payload.issue;
const [command, argument] = getCommand(body);

if (!argument) return;

const options = split(argument);

try {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/__tests__/__snapshots__/getCommand.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Array [
]
`;

exports[`should return command without argument 1`] = `
Array [
"/polls",
undefined,
]
`;

exports[`should return only one command 1`] = `
Array [
"/polls 4 5 6",
Expand Down
9 changes: 9 additions & 0 deletions src/utils/__tests__/getCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ it('should return the first matched command', () => {
`;
expect(getCommand(body)).toMatchSnapshot();
});

it('should return command without argument', () => {
const body = `
# H1
## H2
/polls
`;
expect(getCommand(body)).toMatchSnapshot();
});