Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: add pull_github_pr.sh #2484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

avikivity
Copy link
Member

Add a script that, given a pull request number, will merge it into the current branch, and add the pull request cover letter as a merge commit. This avoids githubs non-informative merge commits.

If the series contains a single patch, the patch is cherry-picked and the cover letter is discarded.

Adapted from scylladb.

Add a script that, given a pull request number, will merge it into
the current branch, and add the pull request cover letter as a merge
commit. This avoids githubs non-informative merge commits.

If the series contains a single patch, the patch is cherry-picked and
the cover letter is discarded.

Adapted from scylladb.

curl() {
local opts=()
if [[ -n "$GITHUB_LOGIN" && -n "$GITHUB_TOKEN" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

GITHUB_LOGIN and GITHUB_TOKEN are always set, so we don't need to check them here. or, we can do something like:

curl() {
    if [[ ( -z "$GITHUB_LOGIN" || -z "$GITHUB_TOKEN" ) && -f "$gh_hosts" ]]; then
        GITHUB_LOGIN=$(awk '/user:/ { print $2 }' "$gh_hosts")
        GITHUB_TOKEN=$(awk '/oauth_token:/ { print $2 }' "$gh_hosts")
     fi

     if [[ -z "$GITHUB_LOGIN" || -z "$GITHUB_TOKEN" ]]; then
        echo 'Please set $GITHUB_LOGIN and $GITHUB_TOKEN'
        exit 1
    fi

    command curl --user "${GITHUB_LOGIN}:${GITHUB_TOKEN}" "$@"
}

as these two variables are "closer" to this function, and we only set them once they are set by this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that there's no need to check these variables again (we checked above that they must be set, if they aren't, the script exited). I also agree that it's nicer to just use crystal-clear shell syntax like you suggested instead of the bizarre arrays used by Avi's code.
But I wouldn't move the check for these variables into the function - I think it's better to check them up-front in the beginning of the script, like Avi did.

fi

if [ -z "$1" ]; then
echo Please provide a github pull request number
Copy link
Contributor

Choose a reason for hiding this comment

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

can we only use spaces instead of using both tabs and spaces for indent?


PR_NUM=$1
# convert full repo URL to its project/repo part, in case of failure default to origin/master:
REMOTE_SLASH_BRANCH="$(git rev-parse --abbrev-ref --symbolic-full-name @{upstream} \
Copy link
Contributor

Choose a reason for hiding this comment

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

extraneous space after name.

PROJECT=`sed 's/[email protected]://;s#https://github.com/##;s/\.git$//;' <<<"${REMOTE_URL}"`
PR_PREFIX=https://api.github.com/repos/$PROJECT/pulls

echo "Fetching info on PR #$PR_NUM... "
Copy link
Contributor

Choose a reason for hiding this comment

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

extraneous space after ....

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe he wanted "echo -n"?

echo "Fetching info on PR #$PR_NUM... "
PR_DATA=$(curl -s $PR_PREFIX/$PR_NUM)
MESSAGE=$(jq -r .message <<< $PR_DATA)
if [ "$MESSAGE" != null ]
Copy link
Contributor

Choose a reason for hiding this comment

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

to be more consistent with the rest of this script, how about moving "next" to the previous line (and add a ;)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I would do the exact opposite. Having the then on a new line, and no ";", is the more traditional and better looking, syntax.

commit=$(git log --pretty=oneline HEAD..FETCH_HEAD | awk '{print $1}')
message="$(git log -1 "$commit" --format="format:%s%n%n%b")"
if ! git cherry-pick $commit
then
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.

set -e

gh_hosts=~/.config/gh/hosts.yml
jenkins_url="https://jenkins.scylladb.com"
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable is not used.


gh_hosts=~/.config/gh/hosts.yml
jenkins_url="https://jenkins.scylladb.com"
FORCE=$2
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable is not used.

gh_hosts=~/.config/gh/hosts.yml
jenkins_url="https://jenkins.scylladb.com"
FORCE=$2
ORANGE='\033[0;33m'
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable is not used.

jenkins_url="https://jenkins.scylladb.com"
FORCE=$2
ORANGE='\033[0;33m'
NC='\033[0m'
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable is not used.

@nyh
Copy link
Contributor

nyh commented Oct 10, 2024

Add a script that, given a pull request number, will merge it into the current branch, and add the pull request cover letter as a merge commit. This avoids githubs non-informative merge commits.

If the series contains a single patch, the patch is cherry-picked and the cover letter is discarded.

Adapted from scylladb.

Good idea. I actually copied the version of the script from Scylla before we started to add strange Scylla-CI-specific code to it, and have been using it in Seastar (and other projects) ever since, and it works very nicely :-)

Copy link
Contributor

@nyh nyh left a comment

Choose a reason for hiding this comment

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

Thanks. Looks good. Joining @tchaikov I only had a bunch of nitpicks.


set -e

gh_hosts=~/.config/gh/hosts.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, is this ~/.config/gh/hosts.yml something standard? Where is it documented?

Copy link
Member Author

Choose a reason for hiding this comment

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

It comes from the gh application, that I only used in order to establish login credentials once.

exit 1
fi

if [ -z "$1" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Silly nitpick: please consider picking either the newer (circa 1983 ;-)) ksh double bracket ([[) or the old-school single bracket (/bin/[]) - but not mix them both in the same script.


curl() {
local opts=()
if [[ -n "$GITHUB_LOGIN" && -n "$GITHUB_TOKEN" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that there's no need to check these variables again (we checked above that they must be set, if they aren't, the script exited). I also agree that it's nicer to just use crystal-clear shell syntax like you suggested instead of the bizarre arrays used by Avi's code.
But I wouldn't move the check for these variables into the function - I think it's better to check them up-front in the beginning of the script, like Avi did.

fi
done

curl() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider renaming this function. I find it confusing that you take a command that has an existing meaning, and redefine it. The fact that you had to use the obscure builtin "command" is a tell-tale sign it's confusing.

echo "Fetching info on PR #$PR_NUM... "
PR_DATA=$(curl -s $PR_PREFIX/$PR_NUM)
MESSAGE=$(jq -r .message <<< $PR_DATA)
if [ "$MESSAGE" != null ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I would do the exact opposite. Having the then on a new line, and no ";", is the more traditional and better looking, syntax.

PROJECT=`sed 's/[email protected]://;s#https://github.com/##;s/\.git$//;' <<<"${REMOTE_URL}"`
PR_PREFIX=https://api.github.com/repos/$PROJECT/pulls

echo "Fetching info on PR #$PR_NUM... "
Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe he wanted "echo -n"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants