Skip to content

ci: scripts to review PRs locally#24623

Closed
mhevery wants to merge 6 commits into
angular:masterfrom
mhevery:review_pr_script
Closed

ci: scripts to review PRs locally#24623
mhevery wants to merge 6 commits into
angular:masterfrom
mhevery:review_pr_script

Conversation

@mhevery

@mhevery mhevery commented Jun 22, 2018

Copy link
Copy Markdown
Contributor

No description provided.

@mhevery mhevery force-pushed the review_pr_script branch from 45ae87c to b2d7566 Compare June 22, 2018 05:33
@mhevery mhevery added the target: major This PR is targeted for the next major release label Jun 22, 2018
@mhevery mhevery requested a review from alxhub June 22, 2018 05:43
Comment thread scripts/github/push-pr Outdated


# 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`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe many of our scripts use a TOKEN environment variable to avoid Github request limits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread scripts/github/review-pr Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer it if the script failed if:

  1. The current branch is not master, or
  2. 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for clean state.

Comment thread docs/PR_REVIEW.md Outdated
cef93a51b (pr/24623_top) ci: scripts to review PRs locally
```

### 5. Pushing local edits pack to the PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pack --> back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread scripts/github/push-pr Outdated

case $key in
--force)
FORCE=-f

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                   😱   😱                                                      😱                     
         😱             😱                                                    😱                       
     😱              😱                                                           😱      😱            
        😱         😱      😱        😱                                 😱           😱    😱      😱       
    😱                         😱   😱     😱                                                 😱         
        😱              😱                                                   😱                        
         😱                                               😱  😱                        😱  😱           

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-f is evil.
Always --force-with-lease 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not know about --force-with-lease updated with it. :-)

Comment thread docs/PR_REVIEW.md Outdated
echo "# here is a change" >> docs/PR_REVIEW.md
```

### 4. Creating a SHA from local Edit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect terminology: SHA is the fingerprint of a commit, you mean the "commit" not "fingerprint of a commit" here.

Maybe say: "Committing local changes" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread scripts/github/push-pr Outdated
echo
echo "$0 PR_NUMBER [--force]"
echo
echo --force Continues even if PR status is not green.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"not green" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy pasta. Fixed

Comment thread scripts/github/push-pr Outdated
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed to write future scripts in shelljs because bash scripts are hard to maintain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewritten as shelljs

@mhevery mhevery left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/github/push-pr Outdated
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewritten as shelljs

Comment thread scripts/github/push-pr Outdated

case $key in
--force)
FORCE=-f

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not know about --force-with-lease updated with it. :-)

Comment thread scripts/github/push-pr Outdated
echo
echo "$0 PR_NUMBER [--force]"
echo
echo --force Continues even if PR status is not green.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy pasta. Fixed

Comment thread scripts/github/push-pr Outdated


# 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`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread scripts/github/review-pr Outdated
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for clean state.

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Jun 24, 2018
Comment thread docs/PR_REVIEW.md Outdated
nothing added to commit but untracked files present (use "git add" to track)
```

Use your IDE to review the untractked files as needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untracked typo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread docs/PR_REVIEW.md Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"which denote the PR start and end SHAs"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread docs/PR_REVIEW.md Outdated

### 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"we have to reverse the reset"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread docs/PR_REVIEW.md
Run `git commit --all --fixup HEAD` to create a `fixup!` commit.

```
$ git commit --all --fixup HEAD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment.

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for a handful of typos

let warnNoToken = true;

async function githubGet(path) {
const token = process.env['TOKEN'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOKEN is a bit generic. Something like GITHUB_TOKEN would be preferrable imo.

@mhevery mhevery Jun 25, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread scripts/github/push-pr Outdated
forceWithLease = ' --force-with-lease';
} else {
shell.echo('Unexpected argument: ', arg);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation 😇

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread scripts/github/push-pr
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.`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\if --> if

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! That explains the weird escaping 😁
OOC, why does the file have no extension (.js for example)?

Comment thread scripts/github/push-pr Outdated

if (require.main === module) {
main(process.argv.splice(2)).then(
(v) => process.exitCode = v ? 0 : 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ? 0 : 1 part seems confusing (and redundant?).

@mhevery mhevery Jun 25, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,95 @@
/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent file naming (git_util vs git-util).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

The repo is full of both `_`- and `-`-separated filenames 😁
I was mainly referring to `merge-pr` and `push-pr` (vs `git_util`).

Comment thread scripts/github/review-pr Outdated
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`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with ${prNumber} SHA\(s\) --> with ${prShaCount} SHA(s)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@mhevery mhevery force-pushed the review_pr_script branch from 2804b2d to 3f87e95 Compare June 25, 2018 15:32
@mhevery mhevery closed this in f841e36 Jun 25, 2018
Comment thread scripts/github/push-pr
if (require.main === module) {
main(process.argv.splice(2)).then(
(v) => process.exitCode = v ? 0 : 1,
(v) => process.exitCode,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this can't be right. Statement no longer has side-effects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. The = v part should stay (only the ? 0 : 1 was redundant).
Feel free to submit a PR with the fix, @JoostK 😉

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants