Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit adec980

Browse files
authoredApr 29, 2024··
Merge branch 'master' into script-ci-spec-validation
2 parents b49f4a1 + 7c0c43c commit adec980

4 files changed

+141
-36
lines changed
 

‎.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ jobs:
5959
body: `Hello, @${{ github.actor }}! 👋🏼
6060
This PR is not up to date with the base branch and can't be merged.
6161
Please update your branch manually with the latest version of the base branch.
62-
PRO-TIP: Add a comment to your PR with the text: \`/au\` or \`/autoupdate\` and our bot will take care of updating the branch in the future. The only requirement for this to work is to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in your PR.
62+
PRO-TIP: To request an update from the upstream branch, simply comment \`/u\` or \`/update\` and our bot will handle the update operation promptly.
63+
64+
The only requirement for this to work is to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in your PR. Also the update will not work if your fork is located in an organization, not under your personal profile.
6365
Thanks 😄`
6466
})
6567
}

‎.github/workflows/autoupdate.yml

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# This action is centrally managed in https://github.com/asyncapi/.github/
2-
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
3-
4-
# This workflow is designed to work with:
5-
# - autoapprove and automerge workflows for dependabot and asyncapibot.
6-
# - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against
7-
8-
# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
9-
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks
10-
11-
name: autoupdate
12-
13-
on:
14-
push:
15-
branches-ignore:
16-
- 'version-bump/**'
17-
- 'dependabot/**'
18-
- 'bot/**'
19-
- 'all-contributors/**'
20-
21-
jobs:
22-
autoupdate-for-bot:
23-
if: startsWith(github.repository, 'asyncapi/')
24-
name: Autoupdate autoapproved PR created in the upstream
25-
runs-on: ubuntu-latest
26-
steps:
27-
- name: Autoupdating
28-
uses: docker://chinthakagodawita/autoupdate-action:v1
29-
env:
30-
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}'
31-
PR_FILTER: "labelled"
32-
PR_LABELS: "autoupdate"
33-
PR_READY_STATE: "ready_for_review"
34-
MERGE_CONFLICT_ACTION: "ignore"
1+
# This action is centrally managed in https://github.com/asyncapi/.github/
2+
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
3+
4+
# This workflow is designed to work with:
5+
# - autoapprove and automerge workflows for dependabot and asyncapibot.
6+
# - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against
7+
8+
# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
9+
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks
10+
11+
name: autoupdate
12+
13+
on:
14+
push:
15+
branches-ignore:
16+
- 'version-bump/**'
17+
- 'dependabot/**'
18+
- 'bot/**'
19+
- 'all-contributors/**'
20+
21+
jobs:
22+
autoupdate-for-bot:
23+
if: startsWith(github.repository, 'asyncapi/')
24+
name: Autoupdate autoapproved PR created in the upstream
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Autoupdating
28+
uses: docker://chinthakagodawita/autoupdate-action:v1
29+
env:
30+
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}'
31+
PR_FILTER: "labelled"
32+
PR_LABELS: "autoupdate"
33+
PR_READY_STATE: "ready_for_review"
34+
MERGE_CONFLICT_ACTION: "ignore"

‎.github/workflows/help-command.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
- \`/please-take-a-look\` or \`/ptal\` - This comment will add a comment to the PR asking for attention from the reviewrs who have not reviewed the PR yet.
3535
- \`/ready-to-merge\` or \`/rtm\` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added
3636
- \`/do-not-merge\` or \`/dnm\` - This comment will block automerging even if all conditions are met and ready-to-merge label is added
37-
- \`/autoupdate\` or \`/au\` - This comment will add \`autoupdate\` label to the PR and keeps your PR up-to-date to the target branch's future changes. Unless there is a merge conflict or it is a draft PR.`
37+
- \`/autoupdate\` or \`/au\` - This comment will add \`autoupdate\` label to the PR and keeps your PR up-to-date to the target branch's future changes. Unless there is a merge conflict or it is a draft PR. (Currently only works for upstream branches.)
38+
- \`/update\` or \`/u\` - This comment will update the PR with the latest changes from the target branch. Unless there is a merge conflict or it is a draft PR. NOTE: this only updates the PR once, so if you need to update again, you need to call the command again.`
3839
})
3940

4041
create_help_comment_issue:

‎.github/workflows/update-pr.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# This workflow is centrally managed in https://github.com/asyncapi/.github/
2+
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
3+
4+
# This workflow will run on every comment with /update or /u. And will create merge-commits for the PR.
5+
# This also works with forks, not only with branches in the same repository/organization.
6+
# Currently, does not work with forks in different organizations.
7+
8+
# This workflow will be distributed to all repositories in the AsyncAPI organization
9+
10+
name: Update PR branches from fork
11+
12+
on:
13+
issue_comment:
14+
types: [created]
15+
16+
jobs:
17+
update-pr:
18+
if: >
19+
startsWith(github.repository, 'asyncapi/') &&
20+
github.event.issue.pull_request &&
21+
github.event.issue.state != 'closed' && (
22+
contains(github.event.comment.body, '/update') ||
23+
contains(github.event.comment.body, '/u')
24+
)
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Get Pull Request Details
28+
id: pr
29+
uses: actions/github-script@v7
30+
with:
31+
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
32+
previews: 'merge-info-preview' # https://docs.github.com/en/graphql/overview/schema-previews#merge-info-preview-more-detailed-information-about-a-pull-requests-merge-state-preview
33+
script: |
34+
const prNumber = context.payload.issue.number;
35+
core.debug(`PR Number: ${prNumber}`);
36+
const { data: pr } = await github.rest.pulls.get({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
pull_number: prNumber
40+
});
41+
42+
// If the PR has conflicts, we don't want to update it
43+
const updateable = ['behind', 'blocked', 'unknown', 'draft', 'clean'].includes(pr.mergeable_state);
44+
console.log(`PR #${prNumber} is ${pr.mergeable_state} and is ${updateable ? 'updateable' : 'not updateable'}`);
45+
core.setOutput('updateable', updateable);
46+
47+
core.debug(`Updating PR #${prNumber} with head ${pr.head.sha}`);
48+
49+
return {
50+
id: pr.node_id,
51+
number: prNumber,
52+
head: pr.head.sha,
53+
}
54+
- name: Update the Pull Request
55+
if: steps.pr.outputs.updateable == 'true'
56+
uses: actions/github-script@v7
57+
with:
58+
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
59+
script: |
60+
const mutation = `mutation update($input: UpdatePullRequestBranchInput!) {
61+
updatePullRequestBranch(input: $input) {
62+
pullRequest {
63+
mergeable
64+
}
65+
}
66+
}`;
67+
68+
const pr_details = ${{ steps.pr.outputs.result }};
69+
70+
try {
71+
const { data } = await github.graphql(mutation, {
72+
input: {
73+
pullRequestId: pr_details.id,
74+
expectedHeadOid: pr_details.head,
75+
}
76+
});
77+
} catch (GraphQLError) {
78+
core.debug(GraphQLError);
79+
if (
80+
GraphQLError.name === 'GraphqlResponseError' &&
81+
GraphQLError.errors.some(
82+
error => error.type === 'FORBIDDEN' || error.type === 'UNAUTHORIZED'
83+
)
84+
) {
85+
// Add comment to PR if the bot doesn't have permissions to update the PR
86+
const comment = `Hi @${context.actor}. Update of PR has failed. It can be due to one of the following reasons:
87+
- I don't have permissions to update this PR. To update your fork with upstream using bot you need to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in the PR.
88+
- The fork is located in an organization, not under your personal profile. No solution for that. You are on your own with manual update.
89+
- There may be a conflict in the PR. Please resolve the conflict and try again.`;
90+
91+
await github.rest.issues.createComment({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
issue_number: context.issue.number,
95+
body: comment
96+
});
97+
98+
core.setFailed('Bot does not have permissions to update the PR');
99+
} else {
100+
core.setFailed(GraphQLError.message);
101+
}
102+
}

0 commit comments

Comments
 (0)
Please sign in to comment.