fix: test1 #38
This file contains 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
name: Automerge For Humans | |
on: | |
pull_request_target: | |
types: | |
- labeled | |
- unlabeled | |
- synchronize | |
- opened | |
- edited | |
- ready_for_review | |
- reopened | |
- unlocked | |
jobs: | |
automerge-for-humans: | |
if: | |
github.event.pull_request.draft == false && | |
(github.event.pull_request.user.login != 'asyncapi-bot' && | |
github.event.pull_request.user.login != 'dependabot[bot]' && | |
github.event.pull_request.user.login != 'dependabot-preview[bot]') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: npm install @octokit/core @octokit/plugin-paginate-rest @octokit/rest cross-fetch | |
- name: Get List of authors | |
id: authors | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { Octokit } = require('@octokit/rest'); | |
const { paginateRest } = require('@octokit/plugin-paginate-rest'); | |
const fetch = require('cross-fetch'); | |
const token = process.env.GITHUB_TOKEN; | |
const prNumber = process.env.PR_NUMBER; | |
const repository = process.env.GITHUB_REPOSITORY; | |
async function getCoAuthors() { | |
try { | |
const octokit = new Octokit({ | |
auth: token, | |
request: { | |
fetch, | |
}, | |
}); | |
const commitsResponse = await octokit.paginate("GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", { | |
owner: "asyncapi", | |
repo: repository, | |
pull_number: prNumber, | |
per_page: 100, | |
}); | |
const authors = commitsResponse | |
.map(data => ({ | |
name: data.commit.author.name, | |
email: data.commit.author.email, | |
login: data.commit.author.login, | |
})) | |
.filter(author => author.login !== 'PR_sender_login') | |
.reduce((uniqueAuthors, author) => { | |
if (!uniqueAuthors.some(a => a.email === author.email)) { | |
uniqueAuthors.push(author); | |
} | |
return uniqueAuthors; | |
}, []) | |
.map(author => `Co-authored-by: ${author.name} <${author.email}>`) | |
.join('\n'); | |
console.log(authors); | |
return authors; | |
} catch (error) { | |
console.error('Error fetching commits:', error); | |
return null; | |
} | |
} | |
await getCoAuthors(); | |
- name: Automerge PR | |
uses: pascalgn/[email protected] | |
env: | |
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" | |
PR_NUMBER: ${{ github.event.number }} | |
PR_TITLE: ${{ github.event.pull_request.title }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
MERGE_LABELS: "!do-not-merge,ready-to-merge" | |
MERGE_METHOD: "squash" | |
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description. | |
# Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions | |
MERGE_COMMIT_MESSAGE: "${{ github.event.pull_request.title }} (#${{ github.event.number }})\n\n\n${{ steps.authors.outputs.value }}" | |
MERGE_RETRIES: "20" | |
MERGE_RETRY_SLEEP: "30000" |