From be728dc2dfc9f215205cc5e52fd2154005829715 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 20 Jun 2024 13:09:09 +0200 Subject: [PATCH 1/5] feat: update existing PR - uses same branch and title all the time --- .github/create-cli-pr.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh index aea04baa9..71f8fd0b3 100755 --- a/.github/create-cli-pr.sh +++ b/.github/create-cli-pr.sh @@ -29,7 +29,7 @@ BODY=$(printf "## Changes since last integration of Language Server\n\n\`\`\`\n% pushd $CLI_DIR UPGRADE=$(go run scripts/upgrade-snyk-go-dependencies.go --name=snyk-ls) LS_VERSION=$(echo $UPGRADE | sed 's/.*Sha: \(.*\) URL.*/\1/') - BRANCH=feat/automatic-upgrade-of-ls-to-$LS_VERSION + BRANCH=feat/automatic-upgrade-of-ls git checkout -b $BRANCH git config --global user.email "team-ide@snyk.io" @@ -41,8 +41,15 @@ pushd $CLI_DIR git config --global user.signingkey ./signingkey.pub git commit -am "feat: automatic integration of language server $LS_VERSION" - git push --set-upstream origin $BRANCH - - gh pr create --repo github.com/snyk/cli --base main --head $BRANCH --title "feat(language-server): integrate LS ($LS_VERSION)" --body "$BODY" + git push -f --set-upstream origin $BRANCH + + TITLE="feat(language-server): integrate LS" + PR=$(gh pr list --search "$TITLE" 2>&1 | grep -e "$TITLE" | cut -f1) + if [[ ! $PR ]]; then + echo "Creating new PR" + gh pr create --repo github.com/snyk/cli --base main --head $BRANCH --title "$TITLE" --body "$BODY" + elif + gh pr edit $PR --repo github.com/snyk/cli --body "$BODY" + fi gh pr merge -m --auto popd From a132c2f18a0887126ffd77fd8514d88427ae6d2f Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 20 Jun 2024 13:12:51 +0200 Subject: [PATCH 2/5] fix: syntax error --- .github/create-cli-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh index 71f8fd0b3..306fff49e 100755 --- a/.github/create-cli-pr.sh +++ b/.github/create-cli-pr.sh @@ -48,7 +48,7 @@ pushd $CLI_DIR if [[ ! $PR ]]; then echo "Creating new PR" gh pr create --repo github.com/snyk/cli --base main --head $BRANCH --title "$TITLE" --body "$BODY" - elif + else gh pr edit $PR --repo github.com/snyk/cli --body "$BODY" fi gh pr merge -m --auto From 75be44f528a6901f9f07942fc962ef3014837444 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 20 Jun 2024 13:41:12 +0200 Subject: [PATCH 3/5] fix: branch creation & delete branch after merge --- .github/create-cli-pr.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh index 306fff49e..787a55a4c 100755 --- a/.github/create-cli-pr.sh +++ b/.github/create-cli-pr.sh @@ -18,7 +18,7 @@ set -ex CLI_DIR=$(mktemp -d) -gh repo clone git@github.com:snyk/cli.git $CLI_DIR -- --depth=1 +gh repo clone git@github.com:snyk/cli.git $CLI_DIR pushd "$CLI_DIR/cliv2" LS_COMMIT_HASH=$(grep snyk-ls go.mod| cut -d "-" -f 4) popd @@ -30,7 +30,7 @@ pushd $CLI_DIR UPGRADE=$(go run scripts/upgrade-snyk-go-dependencies.go --name=snyk-ls) LS_VERSION=$(echo $UPGRADE | sed 's/.*Sha: \(.*\) URL.*/\1/') BRANCH=feat/automatic-upgrade-of-ls - git checkout -b $BRANCH + git checkout $BRANCH || git checkout -b $BRANCH git config --global user.email "team-ide@snyk.io" git config --global user.name "Snyk Team IDE" @@ -51,5 +51,5 @@ pushd $CLI_DIR else gh pr edit $PR --repo github.com/snyk/cli --body "$BODY" fi - gh pr merge -m --auto + gh pr merge -m --auto --delete-branch popd From ef0ec7b3cb71913aeb7498cafdbb4947734743b2 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 20 Jun 2024 13:45:45 +0200 Subject: [PATCH 4/5] fix: move upgrade down to reuse commits --- .github/create-cli-pr.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh index 787a55a4c..7de8cb7fd 100755 --- a/.github/create-cli-pr.sh +++ b/.github/create-cli-pr.sh @@ -25,12 +25,13 @@ popd WHAT_CHANGED=$(git whatchanged "$LS_COMMIT_HASH"...HEAD) BODY=$(printf "## Changes since last integration of Language Server\n\n\`\`\`\n%s\n\`\`\`" "$WHAT_CHANGED") +BRANCH=feat/automatic-upgrade-of-ls pushd $CLI_DIR + git checkout $BRANCH || git checkout -b $BRANCH + UPGRADE=$(go run scripts/upgrade-snyk-go-dependencies.go --name=snyk-ls) LS_VERSION=$(echo $UPGRADE | sed 's/.*Sha: \(.*\) URL.*/\1/') - BRANCH=feat/automatic-upgrade-of-ls - git checkout $BRANCH || git checkout -b $BRANCH git config --global user.email "team-ide@snyk.io" git config --global user.name "Snyk Team IDE" From 0aab31db9f041cc522815480710d6fe3510f088c Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 20 Jun 2024 13:50:16 +0200 Subject: [PATCH 5/5] fix: nothing to commit --- .github/create-cli-pr.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh index 7de8cb7fd..15572cc42 100755 --- a/.github/create-cli-pr.sh +++ b/.github/create-cli-pr.sh @@ -41,7 +41,8 @@ pushd $CLI_DIR echo $PUB_SIGNING_KEY > signingkey.pub git config --global user.signingkey ./signingkey.pub - git commit -am "feat: automatic integration of language server $LS_VERSION" + git commit -am "feat: automatic integration of language server $LS_VERSION" || echo "No files to commit" && exit 0 + git push -f --set-upstream origin $BRANCH TITLE="feat(language-server): integrate LS"