diff --git a/.github/boring-cyborg.yml b/.github/boring-cyborg.yml index 8789531ae07..b9097d96115 100644 --- a/.github/boring-cyborg.yml +++ b/.github/boring-cyborg.yml @@ -59,7 +59,7 @@ labelPRBasedOnFilePath: - "**/*.Rd" verifyTitles: - titleRegexp: '^(WIP:?\s*)?GH-[0-9]+|^MINOR: ' + titleRegexp: '^GH-[0-9]+|^MINOR: ' alwaysUsePrTitle: true validateEitherPrOrSingleCommitTitle: false statusTitle: "PR Title" diff --git a/.github/workflows/dev_pr_merged.yml b/.github/workflows/dev_pr_merged.yml new file mode 100644 index 00000000000..86de58101b6 --- /dev/null +++ b/.github/workflows/dev_pr_merged.yml @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: Dev PR merged + +on: + push: + branches: + - main + +permissions: + contents: read + issues: write + +jobs: + resolve: + name: Resolve + if: github.repository == 'apache/arrow' + runs-on: ubuntu-latest + steps: + # A pushed commit that isn't the merge commit of a + # "GH-XXX: ... (#YYY)" pull request is ignored. + - name: Resolve issue + env: + AUTHOR: ${{ github.event.head_commit.author.username }} + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ github.token }} + MESSAGE: ${{ github.event.head_commit.message }} + run: | + set -euo pipefail + + title=${MESSAGE%%$'\n'*} + title=${title%$'\r'} + if [[ ! "${title}" =~ ^GH-([0-9]+).*\ \(#([0-9]+)\)$ ]]; then + echo "Not the merge commit of a GH-XXX pull request: ${title}" + exit 0 + fi + issue_number=${BASH_REMATCH[1]} + pull_request_number=${BASH_REMATCH[2]} + issue_path="repos/${GH_REPO}/issues/${issue_number}" + issue=$(gh api "${issue_path}") + if [ "$(jq 'has("pull_request")' <<< "${issue}")" = "true" ]; then + echo "#${issue_number} is a pull request, not an issue." + exit 0 + fi + + # Assign the issue to the commit author, who is the pull + # request author for a squash merge, if it isn't assigned to + # anyone. GitHub ignores this silently if the author can't be + # assigned. + if [ -n "${AUTHOR}" ] && \ + [ "$(jq '.assignees | length' <<< "${issue}")" -eq 0 ]; then + gh api "${issue_path}/assignees" -f "assignees[]=${AUTHOR}" > /dev/null + fi + + # Keep the milestone of the issue. If the issue doesn't have + # a milestone, use the next major release that doesn't have a + # maintenance branch yet like dev/merge_arrow_pr.py does. + if [ "$(jq '.milestone' <<< "${issue}")" = "null" ]; then + maintenance_versions=$( + gh api --paginate "repos/${GH_REPO}/git/matching-refs/heads/maint-" \ + --jq '.[].ref | ltrimstr("refs/heads/maint-")') + major_versions=$( + gh api --paginate "repos/${GH_REPO}/milestones?per_page=100" \ + --jq '.[] | select(.title | test("^[0-9]+\\.0\\.0$")) | "\(.title):\(.number)"' | + sort -V) + for major_version in ${major_versions}; do + if ! grep -qxF "${major_version%:*}" <<< "${maintenance_versions}"; then + gh api -X PATCH "${issue_path}" \ + -F "milestone=${major_version#*:}" > /dev/null + break + fi + done + fi + + # Close the issue and comment which pull request resolved it + # after that. The merge script may have done them already. + if [ "$(jq -r .state <<< "${issue}")" != "closed" ]; then + gh issue close "${issue_number}" + fi + comment="Issue resolved by pull request ${pull_request_number}" + comments=$(gh api --paginate "${issue_path}/comments" --jq '.[].body') + if ! grep -qxF "${comment}" <<< "${comments}"; then + gh issue comment "${issue_number}" \ + --body "${comment}"$'\n'"${GITHUB_SERVER_URL}/${GH_REPO}/pull/${pull_request_number}" + fi diff --git a/dev/README.md b/dev/README.md index 275e1ae5c92..fcbabe97e3c 100644 --- a/dev/README.md +++ b/dev/README.md @@ -33,8 +33,36 @@ committer. ## How to Merge a Pull Request -Please don't merge PRs using the GitHub Web interface. Instead, run -the following command: +Use the "Squash and merge" button of the GitHub Web interface. Before +you merge, check that: + +* The pull request title is what you want as the commit title: + `GH-XXX: [Component] Title` or `MINOR: [Component] Title`. The + "PR Title" status of the Boring Cyborg app + (`.github/boring-cyborg.yml`) fails unless the title starts with + `GH-XXX` or `MINOR: ` but it doesn't block the merge. Keep the + ` (#YYY)` suffix that GitHub adds to the commit title in the merge + dialog: the workflow below needs it. +* The pull request description is what you want as the commit + message. Remove leftovers of the pull request template in the + merge dialog if needed. You must remove CI directives such as + `[skip ci]`: GitHub doesn't run the workflow below for a commit + with them and you need to close the issue manually. + +After the merge, the "Dev PR merged" GitHub Actions workflow reads +`GH-XXX` and `(#YYY)` from the commit title. It assigns the issue to +the pull request author if it isn't assigned to anyone, sets its +milestone, closes it and comments which pull request resolved the +issue. The existing issue milestone is retained: set it before merging +if the pull request isn't targeted for the next major release. If the +issue doesn't have a milestone, the next major release is used. This +is only done for pull requests to `main`. + +### Merge script + +The merge script is still available for now. It additionally adds +`Authored-by:`, `Co-authored-by:` and `Signed-off-by:` trailers to the +commit message. Run the following command: ```bash dev/merge_arrow_pr.sh diff --git a/dev/release/post-04-website.sh b/dev/release/post-04-website.sh index 41a7ee4a04c..defab0d23e1 100755 --- a/dev/release/post-04-website.sh +++ b/dev/release/post-04-website.sh @@ -75,10 +75,34 @@ rough_n_development_months=$(( git_tag=apache-arrow-${version} git_range=apache-arrow-${previous_version}..${git_tag} -committers_command_line="git shortlog -sn --group=trailer:signed-off-by ${git_range}" contributors_command_line="git shortlog -sn ${git_range}" -committers=$(${committers_command_line}) +# Count the pull requests of the commits in ${git_range} by who merged +# them. We ask GitHub because commits merged with the merge button +# don't have "Signed-off-by:" trailers. +list_committers() { + git log --pretty=%s ${git_range} | + sed -n -E 's/^.* \(#([0-9]+)\)$/\1/p' | + xargs -n 50 | + while read -r -a numbers; do + local query="query {repository(owner: \"apache\", name: \"arrow\") {" + local number + for number in "${numbers[@]}"; do + query+=" pr${number}: pullRequest(number: ${number})" + query+=" {mergedBy {login ... on User {name}}}" + done + query+="}}" + gh api graphql -f query="${query}" \ + --jq '.data.repository[].mergedBy | select(. != null) | + if (.name // "") == "" then .login else .name end' + done | + sort | + uniq -c | + sort -k1,1nr -k2 | + awk '{count = $1; sub(/^ *[0-9]+ /, ""); printf "%6d\t%s\n", count, $0}' +} + +committers=$(set -o pipefail; list_committers) contributors=$(${contributors_command_line}) n_commits=$(git log --pretty=oneline ${git_range} | wc -l) @@ -151,8 +175,7 @@ cat <> "${announce_file}" The following Apache committers merged contributed patches to the repository. -\`\`\`console -$ ${committers_command_line} +\`\`\`text ANNOUNCE echo "${committers}" >> "${announce_file}" diff --git a/docs/source/developers/continuous_integration/overview.rst b/docs/source/developers/continuous_integration/overview.rst index 4ae0e97297c..ddb23693ba7 100644 --- a/docs/source/developers/continuous_integration/overview.rst +++ b/docs/source/developers/continuous_integration/overview.rst @@ -53,6 +53,7 @@ The ``.yml`` files in ``.github/workflows`` are workflows which are run on GitHu - ``@github-actions crossbow submit ...`` - runs the specified Crossbow command - ``@github-actions rebase`` - rebases the PR onto the main branch - ``dev.yml`` - runs any time there is activity on a PR, or a PR is merged; it runs the linter and tests that the PR can be merged +- ``dev_pr_merged.yml`` - runs any time a PR is merged to the main branch; assigns the GitHub issue of the PR to the PR author if needed, sets its milestone and closes it PR housekeeping (component labels, PR title validation and the GitHub issue link in the PR description) is handled by the `Boring Cyborg `_ GitHub App, configured in ``.github/boring-cyborg.yml``. diff --git a/docs/source/developers/overview.rst b/docs/source/developers/overview.rst index 3b877502323..53a40fa6f54 100644 --- a/docs/source/developers/overview.rst +++ b/docs/source/developers/overview.rst @@ -133,8 +133,7 @@ in the end. To make the review process smooth for everyone, try to When tests are passing and the pull request has been approved by the interested parties, a `committer `_ -will merge the pull request. This is done with a -**command-line utility that does a squash merge**. +will merge the pull request. This is done with a **squash merge**. .. dropdown:: Details on squash merge :animate: fade-in-slide-down @@ -147,9 +146,8 @@ will merge the pull request. This is done with a cherry-pick individual patches onto a maintenance branch. Your pull request will appear in the GitHub interface to have been "merged". - In the commit message of that commit, the merge tool adds the pull request - description, a link back to the pull request, and attribution to the contributor - and any co-authors. + The commit message includes the pull request description, a link to the + pull request, and attribution to the contributor and any co-authors. .. _ai-generated-code: diff --git a/docs/source/developers/release.rst b/docs/source/developers/release.rst index fbce61ae9d1..da44d3e0f0c 100644 --- a/docs/source/developers/release.rst +++ b/docs/source/developers/release.rst @@ -105,7 +105,7 @@ assigned. archery release curate Ensure a major version milestone for a follow up release is created on GitHub. This will -automatically be used by our merge script as the new version for issues closed when +automatically be used on merging pull requests as the new version for issues closed when the maintenance branch is created. Patch Releases