-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pr lint check Fixes #782 * undo * ignore more * remove env.GIT_DIFF * only context * run it * remove env.GIT_DIFF * unbreak cache * updates * updates * all types * set -e * don't catch * set -e needed? * debugging * better errors * testing * testing * using returns * using returns * last cleanup * remove debug * touchups * touchups * remove emojis * remove the need for the PR description to be filled in
- Loading branch information
Showing
5 changed files
with
418 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Checks the PR itself for hygiene things. | ||
|
||
name: PR Lint | ||
|
||
on: | ||
pull_request: | ||
# Necessary to re-run if someone edits the PR without a new pushed commit. | ||
types: [opened, edited, synchronize, reopened] | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v2.1.4 | ||
with: | ||
node-version: "12" | ||
|
||
- name: Install all yarn packages | ||
run: | | ||
cd pr-lint | ||
yarn --frozen-lockfile | ||
- name: Run checks | ||
run: | | ||
cd pr-lint | ||
yarn run check |
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,4 +1,5 @@ | ||
/node_modules | ||
/pr-lint/node_modules/ | ||
/build | ||
.env | ||
yarn-debug.log* | ||
|
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,16 @@ | ||
{ | ||
"name": "pr-lint", | ||
"version": "1.0.0", | ||
"main": "src/index.js", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"scripts": { | ||
"check": "node src/index.js" | ||
}, | ||
"dependencies": { | ||
"@actions/github": "4.0.0", | ||
"boxen": "5.0.0" | ||
} | ||
} |
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,63 @@ | ||
const boxen = require("boxen"); | ||
const github = require("@actions/github"); | ||
|
||
async function main() { | ||
// TODO: Consider being super friendly and possibly... | ||
// * Post a comment that is friendly and useful that explains the problems. | ||
// * Just edit the PR title (or whatever it is) if it's easily fixable. | ||
// See https://www.npmjs.com/package/@actions/github for documentation | ||
// about how to use @actions/github to do authenticated things. | ||
const context = github.context; | ||
|
||
const contextPullRequest = 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 { title } = contextPullRequest; | ||
if (title === "Update index.html") { | ||
// This is the default title you get when you use the GitHub UI to | ||
// edit a file and following web form steps to create a PR. | ||
// These PRs are hard to triage and to organize because of the | ||
// rather "useless" title so let's put the onus back on the author | ||
// to come up with a better title. | ||
// See https://github.com/mdn/content/issues/782 | ||
return ( | ||
'Pull request title can\'t just be "Update index.html"\n' + | ||
"Please update the pull request to be more descriptive. " + | ||
"For example 'fix typo on Web/JavaScript'." | ||
); | ||
} | ||
|
||
// No errors or problems! | ||
return null; | ||
} | ||
|
||
main() | ||
.then((ret) => { | ||
if (ret) { | ||
const lines = ret.split("\n"); | ||
console.log( | ||
boxen(lines[0], { padding: 1, margin: 1, borderStyle: "double" }) | ||
); | ||
// Because boxen breaks, in GitHub Actions logging, when multiple lines. | ||
if (lines.length > 1) { | ||
console.log(`\n${lines.slice(1).join("\n")}\n`); | ||
} | ||
process.exitCode = 2; | ||
} else { | ||
console.log( | ||
boxen("Happiness is when nothing's wrong!", { | ||
padding: 1, | ||
margin: 1, | ||
borderStyle: "double", | ||
}) | ||
); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.