Skip to content
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

fix: Test #3

Open
wants to merge 30 commits into
base: test-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 64 additions & 57 deletions .github/workflows/automerge-for-humans-merging.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# 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

# Purpose of this workflow is to allow people to merge PR without a need of maintainer doing it. If all checks are in place (including maintainers approval) - JUST MERGE IT!
name: Automerge For Humans

on:
Expand All @@ -18,77 +14,88 @@ on:

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]') #it runs only if PR actor is not a bot, at least not a bot that we know
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: '18'
node-version: '16'

- name: Install dependencies
run: npm install node-fetch @octokit/core @octokit/plugin-paginate-rest
run: npm install @octokit/core @octokit/plugin-paginate-rest @octokit/rest cross-fetch

- name: Merge PR with Co-Authors

run: |
run: |
const fetch = require('node-fetch');
const { Octokit } = require('@octokit/rest');
const { paginateRest } = require('@octokit/plugin-paginate-rest');

const token = process.env.GITHUB_TOKEN;
const prNumber = process.env.PR_NUMBER;
const prTitle = process.env.PR_TITLE;
const repostory = process.env.GITHUB_REPOSITORY;
- 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');

async function getCoAuthors() {
try {
const octokit = new Octokit({ auth: token });
const commitsResponse = await octokit.paginate("GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", {
owner: "asyncapi",
repo: repostory,
pull_number: prNumber,
per_page: 100,
});
const fetch = require('cross-fetch');

const coAuthors = commitsResponse
.map(commit => ({
name: commit.commit.author.name,
email: commit.commit.author.email,
login: commit.author.login,
}))
.filter(author => author.login !== 'main_author_login') // Replace 'main_author_login' with the main author's 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');
const token = process.env.GITHUB_TOKEN;
const prNumber = process.env.PR_NUMBER;
const repository = process.env.GITHUB_REPOSITORY;

return coAuthors;
} catch (error) {
console.error('Error fetching commits:', error);
return null;
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: repository.split('/')[0],
repo: repository.split('/')[1],
pull_number: ${{ github.event.number }},
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/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6
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 }}
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
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: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}"
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"
MERGE_RETRY_SLEEP: "30000"
42 changes: 42 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// const fetch = require('node-fetch');
// const { Octokit } = require('@octokit/rest');
// const { paginateRest } = require('@octokit/plugin-paginate-rest');
import { Octokit } from '@octokit/rest';
import { paginateRest } from '@octokit/plugin-paginate-rest';

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 });
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');
consoler.log(authors);
return authors;
} catch (error) {
console.error('Error fetching commits:', error);
return null;
}
}
2 changes: 2 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hii
hello
Loading