Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c724f
commit 201a57b
Showing
10 changed files
with
752 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
[ | ||
{ | ||
"url": "https://api.github.com/repos/reviewflow/reviewflow-test/statuses/f354ffb37cf238108fbb4c915f155d925d82a61b", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/302891?v=4", | ||
"id": 15170493986, | ||
"node_id": "SC_kwDOCgFbpc8AAAADiDteIg", | ||
"state": "failure", | ||
"description": "PR is still in draft", | ||
"target_url": null, | ||
"context": "reviewflow-dev", | ||
"created_at": "2021-11-10T16:24:07Z", | ||
"updated_at": "2021-11-10T16:24:07Z", | ||
"creator": { | ||
"login": "reviewflow-dev[bot]", | ||
"id": 47090515, | ||
"node_id": "MDM6Qm90NDcwOTA1MTU=", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/302891?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D", | ||
"html_url": "https://github.com/apps/reviewflow-dev", | ||
"followers_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/followers", | ||
"following_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/subscriptions", | ||
"organizations_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/orgs", | ||
"repos_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/repos", | ||
"events_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/reviewflow-dev%5Bbot%5D/received_events", | ||
"type": "Bot", | ||
"site_admin": false | ||
} | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Probot } from 'probot'; | ||
import type { AppContext } from '../../context/AppContext'; | ||
import { editOpenedPR } from './actions/editOpenedPR'; | ||
import { updateReviewStatus } from './actions/updateReviewStatus'; | ||
import { createPullRequestHandler } from './utils/createPullRequestHandler'; | ||
|
||
export default function convertedToDraft( | ||
app: Probot, | ||
appContext: AppContext, | ||
): void { | ||
createPullRequestHandler( | ||
app, | ||
appContext, | ||
'pull_request.converted_to_draft', | ||
(payload, context, repoContext) => { | ||
return payload.pull_request; | ||
}, | ||
async ( | ||
pullRequest, | ||
context, | ||
repoContext, | ||
reviewflowPrContext, | ||
): Promise<void> => { | ||
/* if repo is not ignored */ | ||
if (reviewflowPrContext) { | ||
await Promise.all([ | ||
updateReviewStatus(pullRequest, context, repoContext, 'dev', { | ||
remove: ['needsReview'], | ||
}), | ||
editOpenedPR( | ||
pullRequest, | ||
context, | ||
repoContext, | ||
reviewflowPrContext, | ||
true, | ||
), | ||
]); | ||
} | ||
}, | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { Probot } from 'probot'; | ||
import pullRequestCommits from '../../../fixtures/pull_request_30_commits.json'; | ||
import pullRequestReadyForReview from '../../../fixtures/pull_request_54.ready_for_review.json'; | ||
import * as initTeamSlack from '../../context/slack/initTeamSlack'; | ||
import { voidTeamSlack } from '../../context/slack/voidTeamSlack'; | ||
import { | ||
initializeProbotApp, | ||
mockAccessToken, | ||
mockLabels, | ||
nock, | ||
} from '../../tests/setup'; | ||
|
||
jest.spyOn(initTeamSlack, 'initTeamSlack').mockResolvedValue(voidTeamSlack()); | ||
|
||
nock.disableNetConnect(); | ||
|
||
describe('edited', (): void => { | ||
let probot: Probot; | ||
|
||
beforeEach(async () => { | ||
probot = await initializeProbotApp(); | ||
mockAccessToken(); | ||
mockLabels(); | ||
}); | ||
|
||
test('add code review label when pr is ready to be review', async (): Promise<void> => { | ||
const scope = nock('https://api.github.com') | ||
.get( | ||
'/repos/reviewflow/reviewflow-test/issues/comments/1?issue_number=54', | ||
) | ||
.times(1) | ||
.reply(200, { | ||
id: 1, | ||
body: '### Options:\n- [ ] <!-- reviewflow-autoMergeWithSkipCi -->Add `[skip ci]` on merge commit\n- [ ] <!-- reviewflow-autoMerge -->Auto merge when this PR is ready and has no failed statuses. (Also has a queue per repo to prevent multiple useless "Update branch" triggers)\n- [x] <!-- reviewflow-deleteAfterMerge -->Automatic branch delete after this PR is merged', | ||
}) | ||
|
||
.get( | ||
'/repos/reviewflow/reviewflow-test/commits/f354ffb37cf238108fbb4c915f155d925d82a61b/check-runs', | ||
) | ||
.times(2) | ||
.reply(200, { check_runs: [] }) | ||
|
||
.get('/repos/reviewflow/reviewflow-test/pulls/54/commits?per_page=100') | ||
.reply(200, pullRequestCommits) | ||
|
||
.post( | ||
'/repos/reviewflow/reviewflow-test/issues/54/labels', | ||
'[":ok_hand: code/needs-review"]', | ||
) | ||
.reply(200, [ | ||
{ | ||
id: 1_210_432_920, | ||
node_id: 'MDU6TGFiZWwxMjEwNDMyOTIw', | ||
url: 'https://api.github.com/repos/reviewflow/reviewflow-test/labels/:ok_hand:%20code/needs-review', | ||
name: ':ok_hand: code/needs-review', | ||
color: 'FFD57F', | ||
default: false, | ||
description: null, | ||
}, | ||
]) | ||
|
||
.post( | ||
'/repos/reviewflow/reviewflow-test/statuses/f354ffb37cf238108fbb4c915f155d925d82a61b', | ||
'{"context":"reviewflow-dev/lint-pr","state":"success","description":"✓ PR is valid"}', | ||
) | ||
.times(1) | ||
.reply(200) | ||
|
||
.post( | ||
'/repos/reviewflow/reviewflow-test/statuses/f354ffb37cf238108fbb4c915f155d925d82a61b', | ||
'{"context":"reviewflow-dev","state":"failure","description":"Awaiting review from: dev. Perhaps request someone ?"}', | ||
) | ||
.times(1) | ||
.reply(200); | ||
|
||
await probot.receive({ | ||
id: '1', | ||
name: pullRequestReadyForReview.event as any, | ||
payload: pullRequestReadyForReview.payload as any, | ||
}); | ||
|
||
expect(scope.pendingMocks()).toEqual([]); | ||
expect(scope.activeMocks()).toEqual([]); | ||
}); | ||
}); |
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,41 @@ | ||
import type { Probot } from 'probot'; | ||
import type { AppContext } from '../../context/AppContext'; | ||
import { editOpenedPR } from './actions/editOpenedPR'; | ||
import { updateReviewStatus } from './actions/updateReviewStatus'; | ||
import { createPullRequestHandler } from './utils/createPullRequestHandler'; | ||
|
||
export default function readyForReview( | ||
app: Probot, | ||
appContext: AppContext, | ||
): void { | ||
createPullRequestHandler( | ||
app, | ||
appContext, | ||
'pull_request.ready_for_review', | ||
(payload, context, repoContext) => { | ||
return payload.pull_request; | ||
}, | ||
async ( | ||
pullRequest, | ||
context, | ||
repoContext, | ||
reviewflowPrContext, | ||
): Promise<void> => { | ||
/* if repo is not ignored */ | ||
if (reviewflowPrContext) { | ||
await Promise.all([ | ||
updateReviewStatus(pullRequest, context, repoContext, 'dev', { | ||
add: ['needsReview'], | ||
}), | ||
editOpenedPR( | ||
pullRequest, | ||
context, | ||
repoContext, | ||
reviewflowPrContext, | ||
true, | ||
), | ||
]); | ||
} | ||
}, | ||
); | ||
} |
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