| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a3df50d commit bbc10f1
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,4 +60,6 @@ jobs: | |||
| 60 | 60 | ncu-config set repo ${{ env.REPOSITORY }} | |
| 61 | 61 | ||
| 62 | 62 | - name: Start CI | |
| 63 | - run: ./tools/actions/start-ci.sh ${{ secrets.GITHUB_TOKEN }} ${{ env.OWNER }} ${{ env.REPOSITORY }} $(echo '${{ steps.get_prs_for_ci.outputs.data }}' | jq '.repository.pullRequests.nodes | map(.number) | .[]') | ||
| 63 | + run: ./tools/actions/start-ci.sh $(echo '${{ steps.get_prs_for_ci.outputs.data }}' | jq '.repository.pullRequests.nodes | map(.number) | .[]') | ||
| 64 | + env: | ||
| 65 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,4 +78,6 @@ jobs: | |||
| 78 | 78 | ncu-config set owner "${OWNER}" | |
| 79 | 79 | ||
| 80 | 80 | - name: Start the commit queue | |
| 81 | - run: ./tools/actions/commit-queue.sh ${OWNER} ${REPOSITORY} ${{ secrets.GITHUB_TOKEN }} $(echo '${{ steps.get_mergable_pull_requests.outputs.data }}' | jq '.repository.pullRequests.nodes | map(.number) | .[]') | ||
| 81 | + run: ./tools/actions/commit-queue.sh ${OWNER} ${REPOSITORY} $(echo '${{ steps.get_mergable_pull_requests.outputs.data }}' | jq '.repository.pullRequests.nodes | map(.number) | .[]') | ||
| 82 | + env: | ||
| 83 | + GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,62 +4,39 @@ set -xe | |||
| 4 | 4 | ||
| 5 | 5 | OWNER=$1 | |
| 6 | 6 | REPOSITORY=$2 | |
| 7 | - GITHUB_TOKEN=$3 | ||
| 8 | - shift 3 | ||
| 7 | + shift 2 | ||
| 9 | 8 | ||
| 10 | 9 | UPSTREAM=origin | |
| 11 | 10 | DEFAULT_BRANCH=master | |
| 12 | 11 | ||
| 13 | - API_URL=https://api.github.com | ||
| 14 | - COMMIT_QUEUE_LABEL='commit-queue' | ||
| 15 | - COMMIT_QUEUE_FAILED_LABEL='commit-queue-failed' | ||
| 16 | - | ||
| 17 | - issueUrl() { | ||
| 18 | - echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}" | ||
| 19 | - } | ||
| 12 | + COMMIT_QUEUE_LABEL="commit-queue" | ||
| 13 | + COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed" | ||
| 20 | 14 | ||
| 21 | 15 | mergeUrl() { | |
| 22 | - echo "$API_URL/repos/${OWNER}/${REPOSITORY}/pulls/${1}/merge" | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - labelsUrl() { | ||
| 26 | - echo "$(issueUrl "${1}")/labels" | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - commentsUrl() { | ||
| 30 | - echo "$(issueUrl "${1}")/comments" | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - gitHubCurl() { | ||
| 34 | - url=$1 | ||
| 35 | - method=$2 | ||
| 36 | - shift 2 | ||
| 37 | - | ||
| 38 | - curl -fsL --request "$method" \ | ||
| 39 | - --url "$url" \ | ||
| 40 | - --header "authorization: Bearer ${GITHUB_TOKEN}" \ | ||
| 41 | - --header 'content-type: application/json' "$@" | ||
| 16 | + echo "repos/${OWNER}/${REPOSITORY}/pulls/${1}/merge" | ||
| 42 | 17 | } | |
| 43 | 18 | ||
| 44 | 19 | commit_queue_failed() { | |
| 45 | - gitHubCurl "$(labelsUrl "${1}")" POST --data '{"labels": ["'"${COMMIT_QUEUE_FAILED_LABEL}"'"]}' | ||
| 20 | + pr=$1 | ||
| 21 | + | ||
| 22 | + gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" | ||
| 46 | 23 | ||
| 47 | 24 | # shellcheck disable=SC2154 | |
| 48 | 25 | cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| 49 | - jq -n --arg content "<details><summary>Commit Queue failed</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>" '{body: $content}' > output.json | ||
| 50 | - cat output.json | ||
| 26 | + body="<details><summary>Commit Queue failed</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>" | ||
| 27 | + echo "$body" | ||
| 51 | 28 | ||
| 52 | - gitHubCurl "$(commentsUrl "${1}")" POST --data @output.json | ||
| 29 | + gh pr comment "$pr" --body "$body" | ||
| 53 | 30 | ||
| 54 | - rm output output.json | ||
| 31 | + rm output | ||
| 55 | 32 | } | |
| 56 | 33 | ||
| 57 | 34 | # TODO(mmarchini): should this be set with whoever added the label for each PR? | |
| 58 | 35 | git config --local user.email "github-bot@iojs.org" | |
| 59 | 36 | git config --local user.name "Node.js GitHub Bot" | |
| 60 | 37 | ||
| 61 | 38 | for pr in "$@"; do | |
| 62 | - gitHubCurl "$(labelsUrl "$pr")" GET > labels.json | ||
| 39 | + gh pr view "$pr" --json labels --jq ".labels" > labels.json | ||
| 63 | 40 | # Skip PR if CI was requested | |
| 64 | 41 | if jq -e 'map(.name) | index("request-ci")' < labels.json; then | |
| 65 | 42 | echo "pr ${pr} skipped, waiting for CI to start" | |
@@ -73,7 +50,7 @@ for pr in "$@"; do | |||
| 73 | 50 | fi | |
| 74 | 51 | ||
| 75 | 52 | # Delete the commit queue label | |
| 76 | - gitHubCurl "$(labelsUrl "$pr")"/"$COMMIT_QUEUE_LABEL" DELETE | ||
| 53 | + gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL" | ||
| 77 | 54 | ||
| 78 | 55 | if jq -e 'map(.name) | index("commit-queue-squash")' < labels.json; then | |
| 79 | 56 | MULTIPLE_COMMIT_POLICY="--fixupAll" | |
@@ -106,14 +83,18 @@ for pr in "$@"; do | |||
| 106 | 83 | continue | |
| 107 | 84 | fi | |
| 108 | 85 | else | |
| 109 | - # If there's only one commit, we can use the Squash and Merge feature from GitHub | ||
| 86 | + # If there's only one commit, we can use the Squash and Merge feature from GitHub. | ||
| 87 | + # TODO: use `gh pr merge` when the GitHub CLI allows to customize the commit title (https://github.com/cli/cli/issues/1023). | ||
| 110 | 88 | jq -n \ | |
| 111 | 89 | --arg title "$(git log -1 --pretty='format:%s')" \ | |
| 112 | 90 | --arg body "$(git log -1 --pretty='format:%b')" \ | |
| 113 | 91 | --arg head "$(grep 'Fetched commits as' output | cut -d. -f3 | xargs git rev-parse)" \ | |
| 114 | 92 | '{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json | |
| 115 | 93 | cat output.json | |
| 116 | - gitHubCurl "$(mergeUrl "$pr")" PUT --data @output.json > output | ||
| 94 | + if ! gh api -X PUT "$(mergeUrl "$pr")" --input output.json > output; then | ||
| 95 | + commit_queue_failed "$pr" | ||
| 96 | + continue | ||
| 97 | + fi | ||
| 117 | 98 | cat output | |
| 118 | 99 | if ! commits="$(jq -r 'if .merged then .sha else error("not merged") end' < output)"; then | |
| 119 | 100 | commit_queue_failed "$pr" | |
@@ -124,9 +105,9 @@ for pr in "$@"; do | |||
| 124 | 105 | ||
| 125 | 106 | rm output | |
| 126 | 107 | ||
| 127 | - gitHubCurl "$(commentsUrl "$pr")" POST --data '{"body": "Landed in '"$commits"'"}' | ||
| 108 | + gh pr comment "$pr" --body "Landed in $commits" | ||
| 128 | 109 | ||
| 129 | - [ -z "$MULTIPLE_COMMIT_POLICY" ] && gitHubCurl "$(issueUrl "$pr")" PATCH --data '{"state": "closed"}' | ||
| 110 | + [ -z "$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr" | ||
| 130 | 111 | done | |
| 131 | 112 | ||
| 132 | 113 | rm -f labels.json | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,31 +2,11 @@ | |||
| 2 | 2 | ||
| 3 | 3 | set -xe | |
| 4 | 4 | ||
| 5 | - GITHUB_TOKEN=$1 | ||
| 6 | - OWNER=$2 | ||
| 7 | - REPOSITORY=$3 | ||
| 8 | - API_URL=https://api.github.com | ||
| 9 | - REQUEST_CI_LABEL='request-ci' | ||
| 10 | - REQUEST_CI_FAILED_LABEL='request-ci-failed' | ||
| 11 | - shift 3 | ||
| 12 | - | ||
| 13 | - issueUrl() { | ||
| 14 | - echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}" | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - labelsUrl() { | ||
| 18 | - echo "$(issueUrl "${1}")/labels" | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - commentsUrl() { | ||
| 22 | - echo "$(issueUrl "${1}")/comments" | ||
| 23 | - } | ||
| 5 | + REQUEST_CI_LABEL="request-ci" | ||
| 6 | + REQUEST_CI_FAILED_LABEL="request-ci-failed" | ||
| 24 | 7 | ||
| 25 | 8 | for pr in "$@"; do | |
| 26 | - curl -sL --request DELETE \ | ||
| 27 | - --url "$(labelsUrl "$pr")"/"$REQUEST_CI_LABEL" \ | ||
| 28 | - --header "authorization: Bearer ${GITHUB_TOKEN}" \ | ||
| 29 | - --header 'content-type: application/json' | ||
| 9 | + gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL" | ||
| 30 | 10 | ||
| 31 | 11 | ci_started=yes | |
| 32 | 12 | rm -f output; | |
@@ -35,19 +15,11 @@ for pr in "$@"; do | |||
| 35 | 15 | ||
| 36 | 16 | if [ "$ci_started" = "no" ]; then | |
| 37 | 17 | # Do we need to reset? | |
| 38 | - curl -sL --request PUT \ | ||
| 39 | - --url "$(labelsUrl "$pr")" \ | ||
| 40 | - --header "authorization: Bearer ${GITHUB_TOKEN}" \ | ||
| 41 | - --header 'content-type: application/json' \ | ||
| 42 | - --data '{"labels": ["'"${REQUEST_CI_FAILED_LABEL}"'"]}' | ||
| 43 | - | ||
| 44 | - jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" '{body: $content}' > output.json | ||
| 45 | - | ||
| 46 | - curl -sL --request POST \ | ||
| 47 | - --url "$(commentsUrl "$pr")" \ | ||
| 48 | - --header "authorization: Bearer ${GITHUB_TOKEN}" \ | ||
| 49 | - --header 'content-type: application/json' \ | ||
| 50 | - --data @output.json | ||
| 18 | + gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL" | ||
| 19 | + | ||
| 20 | + jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" > output.json | ||
| 21 | + | ||
| 22 | + gh pr comment "$pr" --body-file output.json | ||
| 51 | 23 | ||
| 52 | 24 | rm output.json; | |
| 53 | 25 | fi | |
| Back | FazBrowse Home | New Git URL |
0 commit comments