-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Attempt at adding WIP support. * Fix call. * Run checks on push as well. * Attemt to fix. * Attemt to fix. * Attemt to fix. * Attemt to fix. * Attemt to fix. * Attempt to run on synchronize. * Log response of status update. * Fix syntax error. * Pass along owner and repo. * Update wording and remove logging. * Update wording. * Update README. * Update wording again. * Move script inside "src". * Fix import.
- Loading branch information
Showing
4 changed files
with
71 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,3 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const validatePrTitle = require('./src/validatePrTitle'); | ||
|
||
async function run() { | ||
try { | ||
const client = new github.GitHub(process.env.GITHUB_TOKEN); | ||
|
||
// The pull request info on the context isn't up to date. When | ||
// the user updates the title and re-runs the workflow, it would | ||
// be outdated. Therefore fetch the pull request via the REST API | ||
// to ensure we use the current title. | ||
const contextPullRequest = github.context.payload.pull_request; | ||
const {data: pullRequest} = await client.pulls.get({ | ||
owner: contextPullRequest.base.user.login, | ||
repo: contextPullRequest.base.repo.name, | ||
pull_number: contextPullRequest.number | ||
}); | ||
|
||
await validatePrTitle(pullRequest.title); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
const run = require('./src'); | ||
|
||
run(); |
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,56 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const validatePrTitle = require('./validatePrTitle'); | ||
|
||
module.exports = async function run() { | ||
try { | ||
const client = new github.GitHub(process.env.GITHUB_TOKEN); | ||
|
||
const contextPullRequest = github.context.payload.pull_request; | ||
if (!contextPullRequest) { | ||
throw new Error( | ||
"This action can only be invoked in `pull_request` events. Otherwise the pull request can't be inferred." | ||
); | ||
} | ||
|
||
const owner = contextPullRequest.base.user.login; | ||
const repo = contextPullRequest.base.repo.name; | ||
|
||
// The pull request info on the context isn't up to date. When | ||
// the user updates the title and re-runs the workflow, it would | ||
// be outdated. Therefore fetch the pull request via the REST API | ||
// to ensure we use the current title. | ||
const {data: pullRequest} = await client.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number: contextPullRequest.number | ||
}); | ||
|
||
// Pull requests that start with "[WIP] " are excluded from the check. | ||
const isWip = /^\[WIP\]\s/.test(pullRequest.title); | ||
const newStatus = isWip ? 'pending' : 'success'; | ||
|
||
// When setting the status to "pending", the checks don't complete. | ||
// https://developer.github.com/v3/repos/statuses/#create-a-status | ||
const response = await client.request( | ||
'POST /repos/:owner/:repo/statuses/:sha', | ||
{ | ||
owner, | ||
repo, | ||
sha: pullRequest.head.sha, | ||
state: newStatus, | ||
target_url: 'https://github.com/amannn/action-semantic-pull-request', | ||
description: isWip | ||
? 'This PR is marked with "[WIP]".' | ||
: 'Ready for review & merge.', | ||
context: 'action-semantic-pull-request' | ||
} | ||
); | ||
|
||
if (!isWip) { | ||
await validatePrTitle(pullRequest.title); | ||
} | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
}; |