-
Notifications
You must be signed in to change notification settings - Fork 64
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 #68 from bobvanderlinden/pr-report-status
Add status reporting
- Loading branch information
Showing
11 changed files
with
420 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function getMyAppId () { | ||
if (process.env.APP_ID) { | ||
return parseInt(process.env.APP_ID, 10) | ||
} | ||
if (process.env.NODE_ENV === 'production') { | ||
throw new Error('No APP_ID defined!') | ||
} | ||
return 1 | ||
} | ||
|
||
export default getMyAppId() |
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,54 @@ | ||
import { PullRequestContext } from './pull-request-handler' | ||
import { PullRequestInfo } from './models' | ||
import { ChecksCreateParams } from '@octokit/rest' | ||
|
||
import myAppId from './myappid' | ||
|
||
export async function updateStatusReportCheck ( | ||
context: PullRequestContext, | ||
pullRequestInfo: PullRequestInfo, | ||
title: string, | ||
summary: string | ||
) { | ||
const myCheckRun = pullRequestInfo.checkRuns | ||
.filter(checkRun => checkRun.app.id === myAppId)[0] | ||
|
||
const checkOptions: { | ||
conclusion: 'neutral', | ||
status: 'completed', | ||
name: string, | ||
completed_at: string, | ||
output: ChecksCreateParams['output'], | ||
owner: string, | ||
repo: string | ||
} = { | ||
conclusion: 'neutral', | ||
status: 'completed', | ||
name: 'auto-merge', | ||
completed_at: new Date().toISOString(), | ||
output: { | ||
title, | ||
summary | ||
}, | ||
owner: pullRequestInfo.baseRef.repository.owner.login, | ||
repo: pullRequestInfo.baseRef.repository.name | ||
} | ||
|
||
if (myCheckRun) { | ||
// Whenever we find an existing check_run from this app, | ||
// we will update that check_run. | ||
await context.github.checks.update({ | ||
check_run_id: myCheckRun.id.toString(), | ||
...checkOptions | ||
}) | ||
} else if (context.config.reportStatus) { | ||
// Whenever we did not find an existing check_run we will | ||
// only create a new one if reportStatus is enabled | ||
// in their repository. | ||
|
||
await context.github.checks.create({ | ||
head_sha: pullRequestInfo.headRefOid, | ||
...checkOptions | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.