Skip to content

Commit

Permalink
WIP: set status to pending instead of conclusion to action_required
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jul 5, 2018
1 parent 5e780ab commit 9106451
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
18 changes: 10 additions & 8 deletions lib/handle-pull-request-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function handlePullRequestChange (app, context) {
state.plan = await getPlan(app, accountId)
state.status = state.plan === 'free' ? await getStatusFree(context) : await getStatusPor(context)

// 2. if status did not change then don’t call .createStatus. Quotas for
// 2. if status did not change then don’t create a new check run. Quotas for
// mutations are more restrictive so we want to avoid them if possible
const currentStatus = await getCurrentStatus(context)

Expand All @@ -36,13 +36,14 @@ async function handlePullRequestChange (app, context) {
}

// 3. Create check run
const conclusion = state.status.wip ? 'action_required' : 'success'
const status = state.status.wip ? 'in_progress' : 'completed'
const conclusion = state.status.wip ? undefined : 'success'
const completedAt = status === 'completed' ? new Date() : undefined

const output = {
title: state.status.wip ? 'Work in progress' : 'Ready for review',
summary: state.status.wip
? `The ${locationLabel[state.status.location]} "${state.status.text}" contains "${state.status.match}".
You can override the status by adding "@wip ready for review" to the end of the pull request description`
? `The ${locationLabel[state.status.location]} "${state.status.text}" contains "${state.status.match}".`
: `No match found based on configuration`,
text: state.plan === 'free'
? `By default, WIP only checks the pull request title for the terms "WIP", "Work in progress" and "🚧".
Expand All @@ -69,7 +70,8 @@ Read more about [WIP configuration](#tbd)`
}
const actions = []

if (state.status.wip) {
if (state.plan === 'pro' && state.status.wip) {
output.summary += '\n\nYou can override the status by adding "@wip ready for review" to the end of the pull request description.'
actions.push({
label: '✅ Ready for review',
description: 'override status to "success"',
Expand All @@ -92,8 +94,8 @@ Read more about [WIP configuration](#tbd)`
name: 'WIP (beta)',
head_branch: '', // workaround for https://github.com/octokit/rest.js/issues/874
head_sha: pullRequest.head.sha,
status: 'completed',
completed_at: new Date(),
status,
completed_at: completedAt,
conclusion,
output,
actions
Expand Down
15 changes: 7 additions & 8 deletions test/integration/free-plan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ test('new pull request with "Test" title', async function (t) {
t.is(createCheckParams.name, 'WIP (beta)')
t.is(createCheckParams.status, 'completed')
t.same(createCheckParams.completed_at, NOW)
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')
t.is(createCheckParams.output.title, 'Ready for review')
t.match(createCheckParams.output.summary, /No match found based on configuration/)
Expand Down Expand Up @@ -85,15 +86,11 @@ test('new pull request with "[WIP] Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.deepEqual(createCheckParams.actions, [{
label: '✅ Ready for review',
description: 'override status to "success"',
identifier: 'override:1'
}])
t.is(createCheckParams.status, 'in_progress')
t.deepEqual(createCheckParams.actions, [])
t.is(createCheckParams.output.title, 'Work in progress')
t.match(createCheckParams.output.summary, /The title "\[WIP\] Test" contains "WIP"/)
t.match(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)
t.notMatch(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)

// check resulting logs
const logParams = this.logMock.info.lastCall.arg
Expand All @@ -120,6 +117,7 @@ test('pending pull request with "Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')

// check resulting logs
Expand All @@ -144,7 +142,7 @@ test('ready pull request with "[WIP] Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')

// check resulting logs
const logParams = this.logMock.info.lastCall.arg
Expand Down Expand Up @@ -216,6 +214,7 @@ test('active marketplace "free" plan', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')

// check resulting logs
Expand Down
20 changes: 12 additions & 8 deletions test/integration/pro-plan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ test('new pull request with "Test" title', async function (t) {
t.is(createCheckParams.name, 'WIP (beta)')
t.is(createCheckParams.status, 'completed')
t.same(createCheckParams.completed_at, NOW)
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')
t.is(createCheckParams.output.title, 'Ready for review')
t.match(createCheckParams.output.summary, /No match found based on configuration/)
Expand Down Expand Up @@ -96,7 +97,7 @@ test('new pull request with "[WIP] Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')
t.deepEqual(createCheckParams.actions, [{
label: '✅ Ready for review',
description: 'override status to "success"',
Expand Down Expand Up @@ -131,6 +132,7 @@ test('pending pull request with "Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')

// check resulting logs
Expand All @@ -155,7 +157,7 @@ test('ready pull request with "[WIP] Test" title', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')

// check resulting logs
const logParams = this.logMock.info.lastCall.arg
Expand Down Expand Up @@ -227,9 +229,9 @@ test('custom term: 🚧', async function (t) {
t.is(createCheckParams.owner, 'wip')
t.is(createCheckParams.repo, 'app')
t.is(createCheckParams.name, 'WIP (beta)')
t.is(createCheckParams.status, 'completed')
t.same(createCheckParams.completed_at, NOW)
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')
t.is(createCheckParams.completed_at, undefined)
t.is(createCheckParams.status, 'in_progress')
t.is(createCheckParams.output.title, 'Work in progress')
t.match(createCheckParams.output.summary, /The title "🚧 Test" contains "🚧"/)
t.match(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)
Expand Down Expand Up @@ -272,7 +274,7 @@ test('custom location: label_name', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')
t.match(createCheckParams.output.summary, /The label "WIP" contains "WIP"/)
t.match(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)
t.match(createCheckParams.output.text, /locations: label_name/)
Expand Down Expand Up @@ -308,7 +310,7 @@ test('custom location: commits', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')
t.match(createCheckParams.output.summary, /The commit subject "WIP: test" contains "WIP"/)
t.match(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)
t.match(createCheckParams.output.text, /locations: commit_subject/)
Expand Down Expand Up @@ -359,7 +361,7 @@ test('complex config', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.conclusion, 'action_required')
t.is(createCheckParams.status, 'in_progress')
t.match(createCheckParams.output.summary, /The commit subject "fixup! test" contains "fixup!"/)
t.match(createCheckParams.output.summary, /You can override the status by adding "@wip ready for review"/)
t.match(createCheckParams.output.text, /locations: commit_subject/)
Expand Down Expand Up @@ -408,6 +410,7 @@ test('override', async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')
t.deepEqual(createCheckParams.actions, [{
label: '🔄 Reset',
Expand Down Expand Up @@ -443,6 +446,7 @@ test('pending pull request with override', {only: true}, async function (t) {

// create new check run
const createCheckParams = this.githubMock.checks.create.lastCall.arg
t.is(createCheckParams.status, 'completed')
t.is(createCheckParams.conclusion, 'success')
t.deepEqual(createCheckParams.actions, [])
t.is(createCheckParams.output.title, 'Ready for review')
Expand Down

0 comments on commit 9106451

Please sign in to comment.