Skip to content

Commit

Permalink
Merge branch 'master' into release/2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncapi-bot authored Apr 19, 2024
2 parents be0ac9f + 4717958 commit bdd4f7f
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ jobs:
body: `Hello, @${{ github.actor }}! 👋🏼
This PR is not up to date with the base branch and can't be merged.
Please update your branch manually with the latest version of the base branch.
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.
PRO-TIP: To request an update from the upstream branch, simply comment \`/u\` or \`/update\` and our bot will handle the update operation promptly.
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.
Thanks 😄`
})
}
Expand Down
68 changes: 34 additions & 34 deletions .github/workflows/autoupdate.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
# 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

# This workflow is designed to work with:
# - autoapprove and automerge workflows for dependabot and asyncapibot.
# - 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

# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks

name: autoupdate

on:
push:
branches-ignore:
- 'version-bump/**'
- 'dependabot/**'
- 'bot/**'
- 'all-contributors/**'

jobs:
autoupdate-for-bot:
if: startsWith(github.repository, 'asyncapi/')
name: Autoupdate autoapproved PR created in the upstream
runs-on: ubuntu-latest
steps:
- name: Autoupdating
uses: docker://chinthakagodawita/autoupdate-action:v1
env:
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}'
PR_FILTER: "labelled"
PR_LABELS: "autoupdate"
PR_READY_STATE: "ready_for_review"
MERGE_CONFLICT_ACTION: "ignore"
# This action is centrally managed in https://github.com/asyncapi/.github/
# 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

# This workflow is designed to work with:
# - autoapprove and automerge workflows for dependabot and asyncapibot.
# - 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

# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks

name: autoupdate

on:
push:
branches-ignore:
- 'version-bump/**'
- 'dependabot/**'
- 'bot/**'
- 'all-contributors/**'

jobs:
autoupdate-for-bot:
if: startsWith(github.repository, 'asyncapi/')
name: Autoupdate autoapproved PR created in the upstream
runs-on: ubuntu-latest
steps:
- name: Autoupdating
uses: docker://chinthakagodawita/autoupdate-action:v1
env:
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}'
PR_FILTER: "labelled"
PR_LABELS: "autoupdate"
PR_READY_STATE: "ready_for_review"
MERGE_CONFLICT_ACTION: "ignore"
90 changes: 90 additions & 0 deletions .github/workflows/bounty-program-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This workflow is centrally managed at https://github.com/asyncapi/.github/
# Don't make changes to this file in this repository, as they will be overwritten with
# changes made to the same file in the abovementioned repository.

# The purpose of this workflow is to allow Bounty Team members
# (https://github.com/orgs/asyncapi/teams/bounty_team) to issue commands to the
# organization's global AsyncAPI bot related to the Bounty Program, while at the
# same time preventing unauthorized users from misusing them.

name: Bounty Program commands

on:
issue_comment:
types:
- created

jobs:
guard-against-unauthorized-use:
if: >
github.actor != ('aeworxet' || 'thulieblack') &&
(
contains(github.event.comment.body, '/bounty' )
)
runs-on: ubuntu-latest

steps:
- name: ❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command
uses: actions/github-script@v6

with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const commentText = `❌ @${{github.actor}} is not authorized to use the Bounty Program's commands.
These commands can only be used by members of the [Bounty Team](https://github.com/orgs/asyncapi/teams/bounty_team).`;
console.log(`❌ @${{github.actor}} made an unauthorized attempt to use a Bounty Program's command.`);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentText
})
add-label-bounty:
if: >
github.actor == ('aeworxet' || 'thulieblack') &&
(
contains(github.event.comment.body, '/bounty' )
)
runs-on: ubuntu-latest
env:
BOUNTY_PROGRAM_LABELS_JSON: |
[
{"name": "bounty", "color": "0e8a16", "description": "Participation in the Bounty Program"}
]
steps:
- name: Add label `bounty`
uses: actions/github-script@v6

with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const BOUNTY_PROGRAM_LABELS = JSON.parse(process.env.BOUNTY_PROGRAM_LABELS_JSON);
let LIST_OF_LABELS_FOR_REPO = await github.rest.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
});
LIST_OF_LABELS_FOR_REPO = LIST_OF_LABELS_FOR_REPO.data.map(key => key.name);
if (!LIST_OF_LABELS_FOR_REPO.includes(BOUNTY_PROGRAM_LABELS[0].name)) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: BOUNTY_PROGRAM_LABELS[0].name,
color: BOUNTY_PROGRAM_LABELS[0].color,
description: BOUNTY_PROGRAM_LABELS[0].description
});
}
console.log('Adding label `bounty`...');
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [BOUNTY_PROGRAM_LABELS[0].name]
})
4 changes: 3 additions & 1 deletion .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
At the moment the following comments are supported in pull requests:

- \`/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.
- \`/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
- \`/do-not-merge\` or \`/dnm\` - This comment will block automerging even if all conditions are met and ready-to-merge label is added
- \`/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.`
- \`/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.)
- \`/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.`
})

create_help_comment_issue:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/please-take-a-look-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
# 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

# It uses Github actions to listen for comments on issues and pull requests and
# if the comment contains /please-take-a-look or /ptal it will add a comment pinging
# the code-owners who are reviewers for PR

name: Please take a Look

on:
issue_comment:
types: [created]

jobs:
ping-for-attention:
if: >
github.event.issue.pull_request &&
github.event.issue.state != 'closed' &&
github.actor != 'asyncapi-bot' &&
(
contains(github.event.comment.body, '/please-take-a-look') ||
contains(github.event.comment.body, '/ptal') ||
contains(github.event.comment.body, '/PTAL')
)
runs-on: ubuntu-latest
steps:
- name: Check for Please Take a Look Command
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const prDetailsUrl = context.payload.issue.pull_request.url;
const { data: pull } = await github.request(prDetailsUrl);
const reviewers = pull.requested_reviewers.map(reviewer => reviewer.login);
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const reviewersWhoHaveReviewed = reviews.map(review => review.user.login);
const reviewersWhoHaveNotReviewed = reviewers.filter(reviewer => !reviewersWhoHaveReviewed.includes(reviewer));
if (reviewersWhoHaveNotReviewed.length > 0) {
const comment = reviewersWhoHaveNotReviewed.filter(reviewer => reviewer !== 'asyncapi-bot-eve' ).map(reviewer => `@${reviewer}`).join(' ');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${comment} Please take a look at this PR. Thanks! :wave:`
});
}
102 changes: 102 additions & 0 deletions .github/workflows/update-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This workflow is centrally managed in https://github.com/asyncapi/.github/
# 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

# This workflow will run on every comment with /update or /u. And will create merge-commits for the PR.
# This also works with forks, not only with branches in the same repository/organization.
# Currently, does not work with forks in different organizations.

# This workflow will be distributed to all repositories in the AsyncAPI organization

name: Update PR branches from fork

on:
issue_comment:
types: [created]

jobs:
update-pr:
if: >
startsWith(github.repository, 'asyncapi/') &&
github.event.issue.pull_request &&
github.event.issue.state != 'closed' && (
contains(github.event.comment.body, '/update') ||
contains(github.event.comment.body, '/u')
)
runs-on: ubuntu-latest
steps:
- name: Get Pull Request Details
id: pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
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
script: |
const prNumber = context.payload.issue.number;
core.debug(`PR Number: ${prNumber}`);
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
// If the PR has conflicts, we don't want to update it
const updateable = ['behind', 'blocked', 'unknown', 'draft', 'clean'].includes(pr.mergeable_state);
console.log(`PR #${prNumber} is ${pr.mergeable_state} and is ${updateable ? 'updateable' : 'not updateable'}`);
core.setOutput('updateable', updateable);
core.debug(`Updating PR #${prNumber} with head ${pr.head.sha}`);
return {
id: pr.node_id,
number: prNumber,
head: pr.head.sha,
}
- name: Update the Pull Request
if: steps.pr.outputs.updateable == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const mutation = `mutation update($input: UpdatePullRequestBranchInput!) {
updatePullRequestBranch(input: $input) {
pullRequest {
mergeable
}
}
}`;
const pr_details = ${{ steps.pr.outputs.result }};
try {
const { data } = await github.graphql(mutation, {
input: {
pullRequestId: pr_details.id,
expectedHeadOid: pr_details.head,
}
});
} catch (GraphQLError) {
core.debug(GraphQLError);
if (
GraphQLError.name === 'GraphqlResponseError' &&
GraphQLError.errors.some(
error => error.type === 'FORBIDDEN' || error.type === 'UNAUTHORIZED'
)
) {
// Add comment to PR if the bot doesn't have permissions to update the PR
const comment = `Hi @${context.actor}. Update of PR has failed. It can be due to one of the following reasons:
- 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.
- The fork is located in an organization, not under your personal profile. No solution for that. You are on your own with manual update.
- There may be a conflict in the PR. Please resolve the conflict and try again.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
core.setFailed('Bot does not have permissions to update the PR');
} else {
core.setFailed(GraphQLError.message);
}
}

0 comments on commit bdd4f7f

Please sign in to comment.