ci: scripts to review PRs locally#24623
Conversation
45ae87c to
b2d7566
Compare
|
|
||
|
|
||
| # Fetch the userame:branchname for the PR | ||
| HEAD_LABEL=`curl -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER | node $BASEDIR/utils/json_extract.js head.label` |
There was a problem hiding this comment.
I believe many of our scripts use a TOKEN environment variable to avoid Github request limits.
| PULL_JSON=`$GHCURL -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER` | ||
| PR_SHA_COUNT=`node $BASEDIR/utils/json_extract.js commits <<< """$PULL_JSON"""` | ||
|
|
||
| ## reset the state of the current repo to a know state so that following commands don't collide. |
There was a problem hiding this comment.
I would prefer it if the script failed if:
- The current branch is not
master, or - If the current branch isn't in a clean state.
Doing otherwise risks losing work in progress if the script is run on a working branch accidentally.
There was a problem hiding this comment.
Added check for clean state.
| cef93a51b (pr/24623_top) ci: scripts to review PRs locally | ||
| ``` | ||
|
|
||
| ### 5. Pushing local edits pack to the PR |
|
|
||
| case $key in | ||
| --force) | ||
| FORCE=-f |
There was a problem hiding this comment.
😱 😱 😱
😱 😱 😱
😱 😱 😱 😱
😱 😱 😱 😱 😱 😱 😱 😱
😱 😱 😱 😱 😱
😱 😱 😱
😱 😱 😱 😱 😱
There was a problem hiding this comment.
-f is evil.
Always --force-with-lease 😁
There was a problem hiding this comment.
did not know about --force-with-lease updated with it. :-)
| echo "# here is a change" >> docs/PR_REVIEW.md | ||
| ``` | ||
|
|
||
| ### 4. Creating a SHA from local Edit |
There was a problem hiding this comment.
incorrect terminology: SHA is the fingerprint of a commit, you mean the "commit" not "fingerprint of a commit" here.
Maybe say: "Committing local changes" ?
There was a problem hiding this comment.
Why don't you just use https://hub.github.com/, it gives you all the scripts and
With hub all I do is:
hub checkout https://github.com/angular/angular/pull/24623/files
# hack hack hack
git commit -p --fixup HEAD
git push
# copy the suggested origin and branch from `git push`
git push mhevery HEAD:review_pr_script
| echo | ||
| echo "$0 PR_NUMBER [--force]" | ||
| echo | ||
| echo --force Continues even if PR status is not green. |
| @@ -0,0 +1,52 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
I thought we agreed to write future scripts in shelljs because bash scripts are hard to maintain
There was a problem hiding this comment.
rewritten as shelljs
mhevery
left a comment
There was a problem hiding this comment.
Fixed all comments, please take another look.
The reason I am not using https://hub.github.com/ is because it does not do anything close to this script.
https://hub.github.com/ has an easy way to check out change, but that is it. It does not know how to reset, do local mods and push back to PR.
| @@ -0,0 +1,52 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
rewritten as shelljs
|
|
||
| case $key in | ||
| --force) | ||
| FORCE=-f |
There was a problem hiding this comment.
did not know about --force-with-lease updated with it. :-)
| echo | ||
| echo "$0 PR_NUMBER [--force]" | ||
| echo | ||
| echo --force Continues even if PR status is not green. |
|
|
||
|
|
||
| # Fetch the userame:branchname for the PR | ||
| HEAD_LABEL=`curl -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER | node $BASEDIR/utils/json_extract.js head.label` |
| PULL_JSON=`$GHCURL -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER` | ||
| PR_SHA_COUNT=`node $BASEDIR/utils/json_extract.js commits <<< """$PULL_JSON"""` | ||
|
|
||
| ## reset the state of the current repo to a know state so that following commands don't collide. |
There was a problem hiding this comment.
Added check for clean state.
| nothing added to commit but untracked files present (use "git add" to track) | ||
| ``` | ||
|
|
||
| Use your IDE to review the untractked files as needed. |
| nothing added to commit but untracked files present (use "git add" to track) | ||
| ``` | ||
|
|
||
| Note that the script created `pr/24623_top` and `pr/24623_base` branches which denote where the PR start and end SHA. |
There was a problem hiding this comment.
"which denote the PR start and end SHAs"?
|
|
||
| ### 4. Creating a Commit From Local Edits | ||
|
|
||
| Since the HEAD has been reset to `pr/24623_base` so that changes show up in `git status` we have to do reverse the reset to only see our local changes. |
There was a problem hiding this comment.
"we have to reverse the reset"
| Run `git commit --all --fixup HEAD` to create a `fixup!` commit. | ||
|
|
||
| ``` | ||
| $ git commit --all --fixup HEAD |
There was a problem hiding this comment.
Should we note that newly added file (that git doesn't know about) will not be included via the --all flag?. They must be added using git add first.
petebacondarwin
left a comment
There was a problem hiding this comment.
LGTM except for a handful of typos
| let warnNoToken = true; | ||
|
|
||
| async function githubGet(path) { | ||
| const token = process.env['TOKEN']; |
There was a problem hiding this comment.
TOKEN is a bit generic. Something like GITHUB_TOKEN would be preferrable imo.
There was a problem hiding this comment.
True, but all other scripts use it so I need to be consistent. We should probably have a separate refactoring to change TOKEN to GITHUB_TOKEN
| forceWithLease = ' --force-with-lease'; | ||
| } else { | ||
| shell.echo('Unexpected argument: ', arg); | ||
| } |
| shell.echo(``); | ||
| shell.echo(`${process.argv[1]} [PR_NUMBER] [--force-with-lease]`); | ||
| shell.echo(``); | ||
| shell.echo(` --force-with-lease Continues even \if change can\'t be fast-forwarded.`); |
There was a problem hiding this comment.
Unfortunately if I don't escape if than the the editor gets confuse and color coding gets messed up. The reason why the editor is confused is that the file does not end with .ts and so the editor thinks it is a shell file.
There was a problem hiding this comment.
Aha! That explains the weird escaping 😁
OOC, why does the file have no extension (.js for example)?
|
|
||
| if (require.main === module) { | ||
| main(process.argv.splice(2)).then( | ||
| (v) => process.exitCode = v ? 0 : 1, |
There was a problem hiding this comment.
The ? 0 : 1 part seems confusing (and redundant?).
| @@ -0,0 +1,95 @@ | |||
| /** | |||
There was a problem hiding this comment.
Inconsistent file naming (git_util vs git-util).
There was a problem hiding this comment.
git_util is consistent with the rest of the repo, but merge-pr is not. merge-pr is the inconsistent one, but I am doing it to be consistent with merge-pr.
There was a problem hiding this comment.
👍
The repo is full of both `_`- and `-`-separated filenames 😁I was mainly referring to `merge-pr` and `push-pr` (vs `git_util`).
| shell.exec(`git branch -D pr/${prNumber}`); | ||
| } | ||
|
|
||
| shell.echo(`Fetching pull request \#${prNumber} with ${prNumber} SHA\(s\) into branch range: pr/${prNumber}_base..pr/${prNumber}_top`); |
There was a problem hiding this comment.
with ${prNumber} SHA\(s\) --> with ${prShaCount} SHA(s)
2804b2d to
3f87e95
Compare
| if (require.main === module) { | ||
| main(process.argv.splice(2)).then( | ||
| (v) => process.exitCode = v ? 0 : 1, | ||
| (v) => process.exitCode, |
There was a problem hiding this comment.
Oops, this can't be right. Statement no longer has side-effects.
There was a problem hiding this comment.
You are right. The = v part should stay (only the ? 0 : 1 was redundant).
Feel free to submit a PR with the fix, @JoostK 😉
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.