Skip to content

Commit

Permalink
createDiscussionRepo github-api method created which fixes #56 (#57)
Browse files Browse the repository at this point in the history
* createDiscussionRepo github-api method created which fixes #56

* made changes based on feedback
  • Loading branch information
itaditya committed Jul 5, 2018
1 parent de104ae commit d09044e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LOG_LEVEL=debug
# Go to https://smee.io/new set this to the URL that you are redirected to.
# WEBHOOK_PROXY_URL=
PERSPECTIVE_API_KEY=
GITHUB_ACCESS_TOKEN=
17 changes: 17 additions & 0 deletions lib/github-api/createDiscussionRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* createDiscussionRepo github-api method used to create a discussion repo named appInstallerName-discussions for a user/org in probot-background-check org in which discussion for users who have been hostile will be held.
* @param {object} github - authenticated github client
* @param {object} data
* @param {string} data.appInstallerName - name of user/org who installed the app.
* @returns {Promise<object>}
*/

module.exports = (github, { appInstallerName }) => {
return github.repos.createForOrg({
org: 'probot-background-check',
name: `${appInstallerName}-discussions`,
description: 'Repo to have discussions about toxic users',
// private: true,
auto_init: true
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
},
"dependencies": {
"probot": "^6.0.0",
"probot": "6.2.1",
"superagent": "^3.8.3"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/createDiscussionRepo.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createDiscussionRepo is working 1`] = `
Array [
Array [
Object {
"auto_init": true,
"description": "Repo to have discussions about toxic users",
"name": "test-org-discussions",
"org": "probot-background-check",
},
],
]
`;
22 changes: 22 additions & 0 deletions test/createDiscussionRepo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const createDiscussionRepo = require('../lib/github-api/createDiscussionRepo')

test('createDiscussionRepo is working', async () => {
const github = {
repos: { createForOrg: jest.fn() }
}

// Call your function, which internally calls your above mock function
await createDiscussionRepo(github, { appInstallerName: 'test-org' })

// Test that your mock function has been called
expect(github.repos.createForOrg).toHaveBeenCalledWith({
org: 'probot-background-check',
name: 'test-org-discussions',
description: 'Repo to have discussions about toxic users',
// private: true,
auto_init: true
})

// Test that your mock function has been called with the right arguments
expect(github.repos.createForOrg.mock.calls).toMatchSnapshot()
})
14 changes: 14 additions & 0 deletions test/sandboxes/createDiscussionRepo.sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('dotenv').config({path: '../../.env'})
const octokit = require('probot/lib/github')()

const createDiscussionRepo = require('../../lib/github-api/createDiscussionRepo')

module.exports = async context => {
octokit.authenticate({
type: 'token',
token: process.env.GITHUB_ACCESS_TOKEN
})
await createDiscussionRepo(octokit, {
appInstallerName: 'test-org'
})
}

0 comments on commit d09044e

Please sign in to comment.