-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #980 from repository-settings/esm-again
- Loading branch information
Showing
31 changed files
with
527 additions
and
49 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Probot } from 'probot' | ||
import nock from 'nock' | ||
import any from '@travi/any' | ||
import settingsBot from '../../index' | ||
import settings from '../../lib/settings' | ||
|
||
nock.disableNetConnect() | ||
|
||
const repository = { | ||
default_branch: 'master', | ||
name: 'botland', | ||
owner: { | ||
name: 'bkeepers-inc', | ||
login: 'bkeepers-inc', | ||
email: null | ||
} | ||
} | ||
|
||
function loadInstance () { | ||
const probot = new Probot({ appId: 1, privateKey: 'test', githubToken: 'test' }) | ||
probot.load(settingsBot) | ||
|
||
return probot | ||
} | ||
|
||
function initializeNock () { | ||
return nock('https://api.github.com') | ||
} | ||
|
||
function teardownNock (githubScope) { | ||
expect(githubScope.pendingMocks()).toStrictEqual([]) | ||
|
||
nock.cleanAll() | ||
} | ||
|
||
function buildPushEvent () { | ||
return { | ||
name: 'push', | ||
payload: { | ||
ref: 'refs/heads/master', | ||
repository, | ||
commits: [{ modified: [settings.FILE_NAME], added: [] }] | ||
} | ||
} | ||
} | ||
|
||
function buildRepositoryEditedEvent () { | ||
return { | ||
name: 'repository.edited', | ||
payload: { | ||
changes: { default_branch: { from: any.word() } }, | ||
repository | ||
} | ||
} | ||
} | ||
|
||
function buildRepositoryCreatedEvent () { | ||
return { | ||
name: 'repository.created', | ||
payload: { repository } | ||
} | ||
} | ||
|
||
function buildTriggerEvent () { | ||
return any.fromList([buildPushEvent(), buildRepositoryCreatedEvent(), buildRepositoryEditedEvent()]) | ||
} | ||
|
||
export { | ||
loadInstance, | ||
initializeNock, | ||
teardownNock, | ||
buildTriggerEvent, | ||
buildRepositoryCreatedEvent, | ||
buildRepositoryEditedEvent, | ||
repository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fs from 'fs' | ||
import { CREATED, NO_CONTENT, OK } from 'http-status-codes' | ||
import Settings from '../../../lib/settings' | ||
import { buildTriggerEvent, initializeNock, loadInstance, repository, teardownNock } from '../common' | ||
|
||
describe('collaborators plugin', function () { | ||
let probot, githubScope | ||
|
||
beforeEach(() => { | ||
githubScope = initializeNock() | ||
probot = loadInstance() | ||
}) | ||
|
||
afterEach(() => { | ||
teardownNock(githubScope) | ||
}) | ||
|
||
it('syncs collaborators', async () => { | ||
const pathToConfig = new URL('../../fixtures/collaborators-config.yml', import.meta.url) | ||
const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8')) | ||
const config = configFile.toString() | ||
githubScope | ||
.get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(Settings.FILE_NAME)}`) | ||
.reply(OK, config) | ||
githubScope.get(`/repos/${repository.owner.name}/${repository.name}/collaborators?affiliation=direct`).reply(OK, [ | ||
{ login: 'travi', permissions: { admin: true } }, | ||
{ login: 'bkeepers', permissions: { push: true } } | ||
]) | ||
githubScope | ||
.put(`/repos/${repository.owner.name}/${repository.name}/collaborators/hubot`, body => { | ||
expect(body).toMatchObject({ permission: 'pull' }) | ||
return true | ||
}) | ||
.reply(CREATED) | ||
githubScope | ||
.put(`/repos/${repository.owner.name}/${repository.name}/collaborators/octokit-bot`, body => { | ||
expect(body).toMatchObject({ permission: 'triage' }) | ||
return true | ||
}) | ||
.reply(CREATED) | ||
githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/collaborators/travi`).reply(NO_CONTENT) | ||
|
||
await probot.receive(buildTriggerEvent()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import fs from 'fs' | ||
import { CREATED, NO_CONTENT, OK } from 'http-status-codes' | ||
import Settings from '../../../lib/settings' | ||
import { buildTriggerEvent, initializeNock, loadInstance, repository, teardownNock } from '../common' | ||
|
||
describe('milestones plugin', function () { | ||
let probot, githubScope | ||
|
||
beforeEach(() => { | ||
githubScope = initializeNock() | ||
probot = loadInstance() | ||
}) | ||
|
||
afterEach(() => { | ||
teardownNock(githubScope) | ||
}) | ||
|
||
it('syncs milestones', async () => { | ||
const pathToConfig = new URL('../../fixtures/milestones-config.yml', import.meta.url) | ||
const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8')) | ||
const config = configFile.toString() | ||
githubScope | ||
.get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(Settings.FILE_NAME)}`) | ||
.reply(OK, config) | ||
githubScope.patch(`/repos/${repository.owner.name}/${repository.name}`).reply(200) | ||
githubScope.get(`/repos/${repository.owner.name}/${repository.name}/milestones?per_page=100&state=all`).reply(OK, [ | ||
{ | ||
number: 42, | ||
title: 'existing-milestone', | ||
description: 'this milestone should get updated', | ||
state: 'open' | ||
}, | ||
{ | ||
number: 8, | ||
title: 'old-milestone', | ||
description: 'this milestone should get deleted', | ||
state: 'closed' | ||
} | ||
]) | ||
githubScope | ||
.post(`/repos/${repository.owner.name}/${repository.name}/milestones`, body => { | ||
expect(body).toMatchObject({ | ||
title: 'new-milestone', | ||
description: 'this milestone should get added', | ||
state: 'open' | ||
}) | ||
return true | ||
}) | ||
.reply(CREATED) | ||
githubScope | ||
.patch(`/repos/${repository.owner.name}/${repository.name}/milestones/42`, body => { | ||
expect(body).toMatchObject({ | ||
title: 'existing-milestone', | ||
description: 'this milestone should get updated', | ||
state: 'closed' | ||
}) | ||
return true | ||
}) | ||
.reply(OK) | ||
githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/milestones/8`).reply(NO_CONTENT) | ||
|
||
await probot.receive(buildTriggerEvent()) | ||
}) | ||
}) |
Oops, something went wrong.