-
Notifications
You must be signed in to change notification settings - Fork 140
Add github milestone labeling #189
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| x() { | ||
| echo "+ $*" >&2 | ||
| "$@" | ||
| } | ||
|
|
||
| max_retry_time_seconds=$(( 30 * 60 )) | ||
| retry_delay_seconds=10 | ||
|
|
||
| END=$(( $(date +%s) + ${max_retry_time_seconds} )) | ||
|
|
||
| while (( $(date +%s) < $END )); do | ||
| x "$@" && exit 0 | ||
| sleep "${retry_delay_seconds}" | ||
| done | ||
|
|
||
| echo "$0: retrying [$*] timed out" >&2 | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: milestone | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash --noprofile --norc -euo pipefail {0} | ||
|
|
||
| jobs: | ||
| set-milestone: | ||
| if: github.repository_owner == 'trinodb' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Get milestone from pom.xml | ||
| run: | | ||
| .github/bin/retry ./mvnw -v | ||
| MILESTONE_NUMBER="$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1)" | ||
| echo "Setting PR milestone to ${MILESTONE_NUMBER}" | ||
| echo "MILESTONE_NUMBER=${MILESTONE_NUMBER}" >> $GITHUB_ENV | ||
| - name: Set milestone to PR | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{secrets.GITHUB_TOKEN}} | ||
| script: | | ||
| // Get pull request number from commit sha | ||
| // 'listPullRequestsAssociatedWithCommit()' lists the merged pull request | ||
| // https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit | ||
| // and https://octokit.github.io/rest.js/v19#repos-list-pull-requests-associated-with-commit | ||
| const pr_response = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| commit_sha: context.sha | ||
| }) | ||
| if (pr_response.data.length === 0) { | ||
| console.log('Pull request not found for commit', context.sha) | ||
| return | ||
| } | ||
| if (pr_response.data.length > 1) { | ||
| console.log(pr_response.data) | ||
| throw 'Expected 1 pull request but found: ' + pr_response.data.length | ||
| } | ||
| const pr_number = pr_response.data[0].number | ||
| console.log('Found pull request', pr_number, 'for commit', context.sha) | ||
|
|
||
| // Get milestone | ||
| const { | ||
| MILESTONE_NUMBER | ||
| } = process.env | ||
| console.log('Milestone number to set', MILESTONE_NUMBER) | ||
|
|
||
| // Find milestone with matching title | ||
| // See https://octokit.github.io/rest.js/v19#pagination | ||
| const milestones = await github.paginate(github.rest.issues.listMilestones, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'all' | ||
| }) | ||
| let milestone = milestones.find(milestone => milestone.title === MILESTONE_NUMBER) | ||
| console.log('Found milestone with title', MILESTONE_NUMBER, milestone) | ||
|
|
||
| // Create new milestone if it doesn't exist | ||
| if (!milestone) { | ||
| const create_response = await github.rest.issues.createMilestone({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: MILESTONE_NUMBER | ||
| }) | ||
| milestone = create_response.data | ||
| console.log('Created new milestone with title', MILESTONE_NUMBER, milestone) | ||
| } | ||
|
|
||
| // Set milestone to PR | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| milestone: milestone.number, | ||
| issue_number: pr_number | ||
| }) | ||
| console.log('Added PR', pr_number, 'to milestone', MILESTONE_NUMBER) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.