├── .gitignore
├── avatar.jpg
├── lib
├── utils
│ ├── get-bounty-link.d.ts
│ ├── bounty-badge.d.ts
│ ├── get-bounty-link.js.map
│ ├── get-bounty-link.js
│ ├── bounty-badge.js.map
│ └── bounty-badge.js
├── index.d.ts
├── index.js.map
└── index.js
├── .travis.yml
├── jest.config.js
├── .env.example
├── test
├── fixtures
│ └── issues.opened.json
└── index.test.ts
├── now.json
├── src
├── utils
│ ├── get-bounty-link.ts
│ └── bounty-badge.ts
└── index.ts
├── .all-contributorsrc
├── tsconfig.json
├── .github
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
├── LICENSE
├── CONTRIBUTING.md
├── README.md
├── package.json
├── CODE_OF_CONDUCT.md
└── app.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .env*
3 |
--------------------------------------------------------------------------------
/avatar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kibibit/bountysource-hunter/master/avatar.jpg
--------------------------------------------------------------------------------
/lib/utils/get-bounty-link.d.ts:
--------------------------------------------------------------------------------
1 | export declare const getBountyLink: (str: string) => string | null;
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - "8.3"
5 | notifications:
6 | disabled: true
7 |
--------------------------------------------------------------------------------
/lib/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Application } from 'probot';
2 | declare const _default: (app: Application) => void;
3 | export = _default;
4 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | roots: ['/src/', '/test/'],
3 | transform: {
4 | '^.+\\.tsx?$': 'ts-jest'
5 | },
6 | testRegex: '(/__tests__/.*|\\.(test|spec))\\.[tj]sx?$',
7 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
8 | }
9 |
--------------------------------------------------------------------------------
/lib/utils/bounty-badge.d.ts:
--------------------------------------------------------------------------------
1 | export declare class BountyBadge {
2 | static isBountyBadgeExists(str: string): boolean;
3 | static generate(bountyLink: string): string;
4 | static embedBadge(body: string, badge: string): string;
5 | private static getIssueIdFromLink;
6 | }
7 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | # The ID of your GitHub App
2 | APP_ID=
3 | WEBHOOK_SECRET=development
4 |
5 | # Use `trace` to get verbose logging or `info` to show less
6 | LOG_LEVEL=debug
7 |
8 | # Go to https://smee.io/new set this to the URL that you are redirected to.
9 | WEBHOOK_PROXY_URL=
10 |
--------------------------------------------------------------------------------
/test/fixtures/issues.opened.json:
--------------------------------------------------------------------------------
1 | {
2 | "action": "opened",
3 | "issue": {
4 | "number": 1,
5 | "user": {
6 | "login": "hiimbex"
7 | }
8 | },
9 | "repository": {
10 | "name": "testing-things",
11 | "owner": {
12 | "login": "hiimbex"
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/utils/get-bounty-link.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"get-bounty-link.js","sourceRoot":"","sources":["../../src/utils/get-bounty-link.ts"],"names":[],"mappings":";;AAAA,IAAM,kBAAkB,GAAG,mDAAmD,CAAC;AAGlE,QAAA,aAAa,GAAG,UAAC,GAAW;IACvC,IAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE7C,OAAO,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAC"}
--------------------------------------------------------------------------------
/lib/utils/get-bounty-link.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var getBountyLinkRegex = /There is a .*?bounty.*?\((.*?)\).* on this issue/m;
4 | exports.getBountyLink = function (str) {
5 | var matches = getBountyLinkRegex.exec(str);
6 | return matches && matches[1];
7 | };
8 | //# sourceMappingURL=get-bounty-link.js.map
--------------------------------------------------------------------------------
/now.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "name": "bountysource-hunter",
4 | "alias": "bountysource-hunter.now.sh",
5 | "public": true,
6 | "type": "npm",
7 | "env": {
8 | "NODE_ENV": "production",
9 | "LOG_LEVEL": "info",
10 | "APP_ID": "26071",
11 | "WEBHOOK_SECRET": "@webhook_secret_hunter",
12 | "PRIVATE_KEY": "@private_key_hunter"
13 | },
14 | "scale": {
15 | "sfo1": {
16 | "min": 1,
17 | "max": 1
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/utils/get-bounty-link.ts:
--------------------------------------------------------------------------------
1 | export const getBountyLink = (str: string, shouldAddBadgeOnZero: boolean) => {
2 | const getBountyLinkRegex = /There is a .*?bounty.*?\((.*?)\).* on this issue/m;
3 | const getBountyLinkZeroRegex = /\[Post a bounty on it!\]\((.*?)\)/m;
4 |
5 | const matches = getBountyLinkRegex.exec(str);
6 | const matchesZero = getBountyLinkZeroRegex.exec(str);
7 |
8 | return (matches && matches[1]) || (shouldAddBadgeOnZero ? (matchesZero && matchesZero[1]) : null);
9 | };
10 |
--------------------------------------------------------------------------------
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "bountysource-hunter",
3 | "projectOwner": "kibibit",
4 | "repoType": "github",
5 | "repoHost": "https://github.com",
6 | "files": [
7 | "README.md"
8 | ],
9 | "imageSize": 100,
10 | "commit": true,
11 | "contributors": [
12 | {
13 | "login": "Thatkookooguy",
14 | "name": "Neil Kalman",
15 | "avatar_url": "https://avatars0.githubusercontent.com/u/10427304?s=460&v=4",
16 | "profile": "https://github.com/Thatkookooguy",
17 | "contributions": [
18 | "infra",
19 | "design",
20 | "code"
21 | ]
22 | }
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": false,
4 | "lib": ["es2015", "es2017"],
5 | "module": "commonjs",
6 | "moduleResolution": "node",
7 | "target": "es5",
8 | "noImplicitReturns": true,
9 | "noFallthroughCasesInSwitch": true,
10 | "noUnusedLocals": false,
11 | "pretty": true,
12 | "strict": true,
13 | "sourceMap": true,
14 | "outDir": "./lib",
15 | "skipLibCheck": true,
16 | "noImplicitAny": true,
17 | "esModuleInterop": true,
18 | "declaration": true,
19 | "resolveJsonModule": true
20 | },
21 | "include": [
22 | "src/**/*"
23 | ],
24 | "compileOnSave": false
25 | }
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/lib/index.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,2DAAwD;AACxD,qDAAmD;AAenD,SAAe,QAAQ,CAAC,OAAgB;;;;YAC9B,IAAI,GAAK,OAAO,CAAC,OAAO,CAAC,KAAK,KAA1B,CAA2B;YAEjC,UAAU,GAAG,+BAAa,CAAC,IAAI,CAAC,CAAC;YAEvC,IAAI,CAAC,UAAU,IAAI,0BAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE;gBACxD,sBAAO;aACR;YAEK,QAAQ,GAAG,0BAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAElD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAC1B,OAAO,CAAC,KAAK,CAAC;gBACZ,IAAI,EAAE,0BAAW,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC;aAC7C,CAAC,CACH,CAAC;;;;CACH;AA7BD,iBAAS,UAAC,GAAgB;IACxB,GAAG,CAAC,EAAE,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,EAAE,QAAQ,CAAC,CAAC;IACrD,+CAA+C;IAC/C,mFAAmF;IACnF,4DAA4D;IAC5D,KAAK;IACL,yCAAyC;IACzC,iCAAiC;IAEjC,+CAA+C;IAC/C,6CAA6C;AAC/C,CAAC,CAAA"}
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ISC License
2 |
3 | Copyright (c) 2019, Neil Kalman
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import { Application, Context } from 'probot' // eslint-disable-line no-unused-vars
2 | import { get } from 'lodash';
3 |
4 | import { getBountyLink } from './utils/get-bounty-link';
5 | import { BountyBadge } from './utils/bounty-badge';
6 |
7 | export = (app: Application) => {
8 | app.on(['issues.opened', 'issues.edited'], addBadge);
9 | }
10 |
11 | async function addBadge(context: Context) {
12 | const { body } = context.payload.issue;
13 |
14 | const addBadgeOnZero = await shouldAddBadgeOnZero(context);
15 |
16 | const bountyLink = getBountyLink(body, addBadgeOnZero);
17 |
18 | if (!bountyLink || BountyBadge.isBountyBadgeExists(body)) {
19 | return;
20 | }
21 |
22 | const newBadge = BountyBadge.generate(bountyLink);
23 |
24 | context.github.issues.update(
25 | context.issue({
26 | body: BountyBadge.embedBadge(body, newBadge),
27 | })
28 | );
29 | }
30 |
31 | function shouldAddBadgeOnZero(context: Context) {
32 | return context.config('config.yml')
33 | .then((config) => get(config, 'bountysourceHunterAddBadgeOnZero', false));
34 | }
35 |
--------------------------------------------------------------------------------
/src/utils/bounty-badge.ts:
--------------------------------------------------------------------------------
1 | export class BountyBadge {
2 | static isBountyBadgeExists(str: string): boolean {
3 | const getBountyBadgeRegex = /\[\!\[Bountysource\]/m;
4 |
5 | return getBountyBadgeRegex.test(str);
6 | }
7 |
8 | static generate(bountyLink: string) {
9 | const issueId = BountyBadge.getIssueIdFromLink(bountyLink);
10 |
11 | return `[](${bountyLink})\r\n\r\n`;
12 | }
13 |
14 | static embedBadge(body: string, badge: string) {
15 | const lines = body.split('\n');
16 |
17 | const before: string[] = [];
18 | const after: string[] = [];
19 |
20 | let foundEndOfTitle = false;
21 |
22 | lines.forEach((line: string) => {
23 | if (!foundEndOfTitle && line.startsWith('#')) {
24 | before.push(line);
25 | return;
26 | }
27 |
28 | foundEndOfTitle = true;
29 |
30 | after.push(line);
31 | });
32 |
33 | return `${before.join('\n')}${badge}${after.join('\n')}`;
34 | }
35 |
36 | private static getIssueIdFromLink(bountyLink: string) {
37 | const getIssueIdRegex = /\/issues\/(\d*)-/;
38 | const matches = getIssueIdRegex.exec(bountyLink);
39 |
40 | return matches && matches[1];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/lib/utils/bounty-badge.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"bounty-badge.js","sourceRoot":"","sources":["../../src/utils/bounty-badge.ts"],"names":[],"mappings":";;AAAA;IAAA;IA4CA,CAAC;IA3CQ,+BAAmB,GAA1B,UAA2B,GAAW;QACpC,IAAM,mBAAmB,GAAG,uBAAuB,CAAC;QAEpD,OAAO,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAEM,oBAAQ,GAAf,UAAgB,UAAkB;QAChC,IAAM,OAAO,GAAG,WAAW,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAE3D,OAAO,wEAAsE,OAAO,WAAM,UAAU,cAAW,CAAC;IAClH,CAAC;IAEM,sBAAU,GAAjB,UAAkB,IAAY,EAAE,KAAa;QAC3C,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE/B,IAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,IAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,eAAe,GAAG,KAAK,CAAC;QAE5B,KAAK,CAAC,OAAO,CAAC,UAAC,IAAY;YACzB,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAC5C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClB,OAAO;aACR;YAED,eAAe,GAAG,IAAI,CAAC;YAEvB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzC,OAAO,KAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAG,CAAC;IAC3D,CAAC;IAEc,8BAAkB,GAAjC,UAAkC,UAAkB;QAClD,IAAM,eAAe,GAAG,kBAAkB,CAAC;QAC3C,IAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEjD,OAAO,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IACH,kBAAC;AAAD,CAAC,AA5CD,IA4CC;AA5CY,kCAAW"}
--------------------------------------------------------------------------------
/lib/utils/bounty-badge.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var BountyBadge = /** @class */ (function () {
4 | function BountyBadge() {
5 | }
6 | BountyBadge.isBountyBadgeExists = function (str) {
7 | var getBountyBadgeRegex = /\[\!\[Bountysource\]/m;
8 | return getBountyBadgeRegex.test(str);
9 | };
10 | BountyBadge.generate = function (bountyLink) {
11 | var issueId = BountyBadge.getIssueIdFromLink(bountyLink);
12 | return "[](" + bountyLink + ")\r\n\r\n";
13 | };
14 | BountyBadge.embedBadge = function (body, badge) {
15 | var lines = body.split('\n');
16 | var before = [];
17 | var after = [];
18 | var foundEndOfTitle = false;
19 | lines.forEach(function (line) {
20 | if (!foundEndOfTitle && line.startsWith('#')) {
21 | before.push(line);
22 | return;
23 | }
24 | foundEndOfTitle = true;
25 | after.push(line);
26 | });
27 | console.log('BEFORE: ', before.join('\n'));
28 | console.log('AFTER: ', after.join('\n'));
29 | return "" + before.join('\n') + badge + after.join('\n');
30 | };
31 | BountyBadge.getIssueIdFromLink = function (bountyLink) {
32 | var getIssueIdRegex = /\/issues\/(\d*)-/;
33 | var matches = getIssueIdRegex.exec(bountyLink);
34 | return matches && matches[1];
35 | };
36 | return BountyBadge;
37 | }());
38 | exports.BountyBadge = BountyBadge;
39 | //# sourceMappingURL=bounty-badge.js.map
--------------------------------------------------------------------------------
/test/index.test.ts:
--------------------------------------------------------------------------------
1 | // You can import your modules
2 | // import index from '../src/index'
3 |
4 | import nock from 'nock'
5 | // Requiring our app implementation
6 | import myProbotApp from '../src'
7 | import { Probot } from 'probot'
8 | // Requiring our fixtures
9 | import payload from './fixtures/issues.opened.json'
10 | const issueCreatedBody = { body: 'Thanks for opening this issue!' }
11 |
12 | nock.disableNetConnect()
13 |
14 | describe('My Probot app', () => {
15 | let probot: any
16 |
17 | beforeEach(() => {
18 | probot = new Probot({ id: 123, cert: 'test' })
19 | // Load our app into probot
20 | const app = probot.load(myProbotApp)
21 |
22 | // just return a test token
23 | app.app = () => 'test'
24 | })
25 |
26 | test('creates a comment when an issue is opened', async (done) => {
27 | // Test that we correctly return a test token
28 | nock('https://api.github.com')
29 | .post('/app/installations/2/access_tokens')
30 | .reply(200, { token: 'test' })
31 |
32 | // Test that a comment is posted
33 | nock('https://api.github.com')
34 | .post('/repos/hiimbex/testing-things/issues/1/comments', (body: any) => {
35 | done(expect(body).toMatchObject(issueCreatedBody))
36 | return true
37 | })
38 | .reply(200)
39 |
40 | // Receive a webhook event
41 | await probot.receive({ name: 'issues', payload })
42 | })
43 | })
44 |
45 | // For more information about testing with Jest see:
46 | // https://facebook.github.io/jest/
47 |
48 | // For more information about using TypeScript in your tests, Jest recommends:
49 | // https://github.com/kulshekhar/ts-jest
50 |
51 | // For more information about testing with Nock see:
52 | // https://github.com/nock/nock
53 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing
2 |
3 | [fork]: /fork
4 | [pr]: /compare
5 | [style]: https://standardjs.com/
6 | [code-of-conduct]: CODE_OF_CONDUCT.md
7 |
8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
9 |
10 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
11 |
12 | ## Issues and PRs
13 |
14 | If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them.
15 |
16 | We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR.
17 |
18 | ## Submitting a pull request
19 |
20 | 1. [Fork][fork] and clone the repository.
21 | 1. Configure and install the dependencies: `npm install`.
22 | 1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so there's no need to lint separately.
23 | 1. Create a new branch: `git checkout -b my-branch-name`.
24 | 1. Make your change, add tests, and make sure the tests still pass.
25 | 1. Push to your fork and [submit a pull request][pr].
26 | 1. Pat your self on the back and wait for your pull request to be reviewed and merged.
27 |
28 | Here are a few things you can do that will increase the likelihood of your pull request being accepted:
29 |
30 | - Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test`.
31 | - Write and update tests.
32 | - Keep your changes as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
33 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
34 |
35 | Work in Progress pull requests are also welcome to get feedback early on, or if there is something blocked you.
36 |
37 | ## Resources
38 |
39 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
40 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
41 | - [GitHub Help](https://help.github.com)
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | bountysource-hunter
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Adds a bounty badge for issues with active bounties
20 |
21 |
22 |
23 | ## Setup
24 |
25 | [Go to the GitHub App](https://github.com/apps/bountysource-hunter) and add it to any of your repositories
26 |
27 | ## Configuration
28 |
29 | Currently, you can set `bountysourceHunterAddBadgeOnZero` to `true` in your configuration if you want to include the badge when there's still no bounty
30 |
31 | ```yml
32 | # .github/config.yml
33 | bountysourceHunterAddBadgeOnZero: true
34 |
35 | ```
36 |
37 | ## Contributing
38 |
39 | If you have suggestions for how bountysource-hunter could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
40 |
41 | For more, check out the [Contributing Guide](CONTRIBUTING.md).
42 |
43 | ## Contributors
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | ## License
52 |
53 | [ISC](LICENSE) © 2019 Neil Kalman
54 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@kibibit/bountysource-hunter",
3 | "version": "1.0.0",
4 | "description": "Adds a bounty badge for issues with active bounties",
5 | "author": "Neil Kalman ",
6 | "license": "ISC",
7 | "repository": "https://github.com//bountysource-hunter.git",
8 | "homepage": "https://github.com//bountysource-hunter",
9 | "bugs": "https://github.com//bountysource-hunter/issues",
10 | "keywords": [
11 | "probot",
12 | "github",
13 | "probot-app"
14 | ],
15 | "scripts": {
16 | "build": "tsc -p tsconfig.json",
17 | "dev": "nodemon --exec \"npm start\"",
18 | "start": "probot run ./lib/index.js",
19 | "lint": "standard **/*.ts --fix",
20 | "test": "echo tests",
21 | "test:real": "jest && standard **/*.ts",
22 | "test:watch": "jest --watch --notify --notifyMode=change --coverage",
23 | "test:cov": "jest --coverage",
24 | "coveralls": "npm run test:cov && cat ./test-results/lcov.info | coveralls",
25 | "travis-deploy-once": "travis-deploy-once",
26 | "semantic-release": "semantic-release",
27 | "contributors:add": "all-contributors add",
28 | "contributors:generate": "all-contributors generate"
29 | },
30 | "release": {
31 | "plugins": [
32 | "@semantic-release/commit-analyzer",
33 | "@semantic-release/release-notes-generator",
34 | "@semantic-release/github",
35 | "@semantic-release/npm",
36 | [
37 | "@semantic-release/git",
38 | {
39 | "assets": false,
40 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
41 | }
42 | ]
43 | ]
44 | },
45 | "dependencies": {
46 | "@types/lodash": "^4.14.121",
47 | "@types/nock": "^9.3.0",
48 | "lodash": "^4.17.11",
49 | "nock": "^10.0.0",
50 | "probot": "^7.2.0",
51 | "typescript": "^3.3.1"
52 | },
53 | "devDependencies": {
54 | "@types/jest": "^24.0.0",
55 | "@types/node": "^11.9.0",
56 | "all-contributors-cli": "^6.1.2",
57 | "eslint-plugin-typescript": "^0.14.0",
58 | "jest": "^24.0.0",
59 | "nodemon": "^1.17.2",
60 | "semantic-release-cli": "^4.1.0",
61 | "smee-client": "^1.0.2",
62 | "standard": "^12.0.1",
63 | "ts-jest": "^24.0.0",
64 | "typescript-eslint-parser": "^22.0.0"
65 | },
66 | "engines": {
67 | "node": ">= 8.3.0"
68 | },
69 | "standard": {
70 | "parser": "typescript-eslint-parser",
71 | "env": [
72 | "jest"
73 | ],
74 | "plugins": [
75 | "typescript"
76 | ]
77 | },
78 | "jest": {
79 | "testEnvironment": "node",
80 | "coverageReporters": [
81 | "json",
82 | "lcov",
83 | "text",
84 | "clover",
85 | "html"
86 | ],
87 | "coverageDirectory": "./test-results",
88 | "reporters": [
89 | "default",
90 | [
91 | "jest-html-reporter",
92 | {
93 | "pageTitle": "achievibit's Test Report",
94 | "outputPath": "./test-results/test-report.html"
95 | }
96 | ]
97 | ]
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | education, socio-economic status, nationality, personal appearance, race,
10 | religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at neilkalman@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 | return new (P || (P = Promise))(function (resolve, reject) {
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
8 | });
9 | };
10 | var __generator = (this && this.__generator) || function (thisArg, body) {
11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13 | function verb(n) { return function (v) { return step([n, v]); }; }
14 | function step(op) {
15 | if (f) throw new TypeError("Generator is already executing.");
16 | while (_) try {
17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18 | if (y = 0, t) op = [op[0] & 2, t.value];
19 | switch (op[0]) {
20 | case 0: case 1: t = op; break;
21 | case 4: _.label++; return { value: op[1], done: false };
22 | case 5: _.label++; y = op[1]; op = [0]; continue;
23 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
24 | default:
25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29 | if (t[2]) _.ops.pop();
30 | _.trys.pop(); continue;
31 | }
32 | op = body.call(thisArg, _);
33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35 | }
36 | };
37 | var get_bounty_link_1 = require("./utils/get-bounty-link");
38 | var bounty_badge_1 = require("./utils/bounty-badge");
39 | function addBadge(context) {
40 | return __awaiter(this, void 0, void 0, function () {
41 | var body, bountyLink, newBadge;
42 | return __generator(this, function (_a) {
43 | body = context.payload.issue.body;
44 | bountyLink = get_bounty_link_1.getBountyLink(body);
45 | if (!bountyLink || bounty_badge_1.BountyBadge.isBountyBadgeExists(body)) {
46 | return [2 /*return*/];
47 | }
48 | newBadge = bounty_badge_1.BountyBadge.generate(bountyLink);
49 | context.github.issues.update(context.issue({
50 | body: bounty_badge_1.BountyBadge.embedBadge(body, newBadge),
51 | }));
52 | return [2 /*return*/];
53 | });
54 | });
55 | }
56 | module.exports = function (app) {
57 | app.on(['issues.opened', 'issues.edited'], addBadge);
58 | // app.on('issues.opened', async (context) => {
59 | // const issueComment = context.issue({ body: 'Thanks for opening this issue!' })
60 | // await context.github.issues.createComment(issueComment)
61 | // })
62 | // For more information on building apps:
63 | // https://probot.github.io/docs/
64 | // To get your app running against GitHub, see:
65 | // https://probot.github.io/docs/development/
66 | };
67 | //# sourceMappingURL=index.js.map
--------------------------------------------------------------------------------
/app.yml:
--------------------------------------------------------------------------------
1 | # This is a GitHub App Manifest. These settings will be used by default when
2 | # initially configuring your GitHub App.
3 | #
4 | # NOTE: changing this file will not update your GitHub App settings.
5 | # You must visit github.com/settings/apps/your-app-name to edit them.
6 | #
7 | # Read more about configuring your GitHub App:
8 | # https://probot.github.io/docs/development/#configuring-a-github-app
9 | #
10 | # Read more about GitHub App Manifests:
11 | # https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/
12 |
13 | # The list of events the GitHub App subscribes to.
14 | # Uncomment the event names below to enable them.
15 | default_events:
16 | # - check_run
17 | # - check_suite
18 | # - commit_comment
19 | # - create
20 | # - delete
21 | # - deployment
22 | # - deployment_status
23 | # - fork
24 | # - gollum
25 | # - issue_comment
26 | - issues
27 | # - label
28 | # - milestone
29 | # - member
30 | # - membership
31 | # - org_block
32 | # - organization
33 | # - page_build
34 | # - project
35 | # - project_card
36 | # - project_column
37 | # - public
38 | # - pull_request
39 | # - pull_request_review
40 | # - pull_request_review_comment
41 | # - push
42 | # - release
43 | # - repository
44 | # - repository_import
45 | # - status
46 | # - team
47 | # - team_add
48 | # - watch
49 |
50 | # The set of permissions needed by the GitHub App. The format of the object uses
51 | # the permission name for the key (for example, issues) and the access type for
52 | # the value (for example, write).
53 | # Valid values are `read`, `write`, and `none`
54 | default_permissions:
55 | # Repository creation, deletion, settings, teams, and collaborators.
56 | # https://developer.github.com/v3/apps/permissions/#permission-on-administration
57 | # administration: read
58 |
59 | # Checks on code.
60 | # https://developer.github.com/v3/apps/permissions/#permission-on-checks
61 | # checks: read
62 |
63 | # Repository contents, commits, branches, downloads, releases, and merges.
64 | # https://developer.github.com/v3/apps/permissions/#permission-on-contents
65 | # contents: read
66 |
67 | # Deployments and deployment statuses.
68 | # https://developer.github.com/v3/apps/permissions/#permission-on-deployments
69 | # deployments: read
70 |
71 | # Issues and related comments, assignees, labels, and milestones.
72 | # https://developer.github.com/v3/apps/permissions/#permission-on-issues
73 | issues: write
74 |
75 | # Search repositories, list collaborators, and access repository metadata.
76 | # https://developer.github.com/v3/apps/permissions/#metadata-permissions
77 | metadata: read
78 |
79 | # Retrieve Pages statuses, configuration, and builds, as well as create new builds.
80 | # https://developer.github.com/v3/apps/permissions/#permission-on-pages
81 | # pages: read
82 |
83 | # Pull requests and related comments, assignees, labels, milestones, and merges.
84 | # https://developer.github.com/v3/apps/permissions/#permission-on-pull-requests
85 | # pull_requests: read
86 |
87 | # Manage the post-receive hooks for a repository.
88 | # https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks
89 | # repository_hooks: read
90 |
91 | # Manage repository projects, columns, and cards.
92 | # https://developer.github.com/v3/apps/permissions/#permission-on-repository-projects
93 | # repository_projects: read
94 |
95 | # Retrieve security vulnerability alerts.
96 | # https://developer.github.com/v4/object/repositoryvulnerabilityalert/
97 | # vulnerability_alerts: read
98 |
99 | # Commit statuses.
100 | # https://developer.github.com/v3/apps/permissions/#permission-on-statuses
101 | # statuses: read
102 |
103 | # Organization members and teams.
104 | # https://developer.github.com/v3/apps/permissions/#permission-on-members
105 | # members: read
106 |
107 | # View and manage users blocked by the organization.
108 | # https://developer.github.com/v3/apps/permissions/#permission-on-organization-user-blocking
109 | # organization_user_blocking: read
110 |
111 | # Manage organization projects, columns, and cards.
112 | # https://developer.github.com/v3/apps/permissions/#permission-on-organization-projects
113 | # organization_projects: read
114 |
115 | # Manage team discussions and related comments.
116 | # https://developer.github.com/v3/apps/permissions/#permission-on-team-discussions
117 | # team_discussions: read
118 |
119 | # Manage the post-receive hooks for an organization.
120 | # https://developer.github.com/v3/apps/permissions/#permission-on-organization-hooks
121 | # organization_hooks: read
122 |
123 | # Get notified of, and update, content references.
124 | # https://developer.github.com/v3/apps/permissions/
125 | # organization_administration: read
126 |
127 |
128 | # The name of the GitHub App. Defaults to the name specified in package.json
129 | # name: My Probot App
130 |
131 | # The homepage of your GitHub App.
132 | # url: https://example.com/
133 |
134 | # A description of the GitHub App.
135 | # description: A description of my awesome app
136 |
137 | # Set to true when your GitHub App is available to the public or false when it is only accessible to the owner of the app.
138 | # Default: true
139 | # public: false
140 |
--------------------------------------------------------------------------------