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 wrong format for Co-authored automerged commits + pagination #263

Open
smoya opened this issue Dec 4, 2023 · 7 comments · May be fixed by #266
Open

Fix wrong format for Co-authored automerged commits + pagination #263

smoya opened this issue Dec 4, 2023 · 7 comments · May be fixed by #266
Labels
area/ci-cd Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. bug Something isn't working good first issue Good for newcomers

Comments

@smoya
Copy link
Member

smoya commented Dec 4, 2023

Describe the bug

Commit Co-authoring allow us to merge PR's and tell Github who were the committers so it does not appear only the PR creator as the author of all the code on it. Unfortunately, it doesn't work at this moment due to a bug in our side.
The way it works is described here.
We basically make it happen in this action.

However, the final commit message contains a wrong format that makes the co-authoring feature fail.

It seems like a format problem: no new line character is being printed (each co-author should appear in new line). Instead, the new line characters appears encoded (%0A) 😞

How to Reproduce

See an example here: asyncapi/parser-js@4799f2a

Expected behavior

Each co-author line (Co-authored-by: ...) should appear in a new line as the documentation says.
Additionally, we should find an alternative to curl + jq or maybe use some bash so we can implement pagination and by pass the limitation of 100 commit results. There are PR's that have more than 100 commits, specially in long-live branches.

@smoya smoya added the bug Something isn't working label Dec 4, 2023
@smoya
Copy link
Member Author

smoya commented Dec 4, 2023

/help

@asyncapi-bot
Copy link

Hello, @smoya! 👋🏼

I'm 🧞🧞🧞 Genie 🧞🧞🧞 from the magic lamp. Looks like somebody needs a hand!

At the moment the following comments are supported in issues:

  • /good-first-issue {js | ts | java | go | docs | design | ci-cd} or /gfi {js | ts | java | go | docs | design | ci-cd} - label an issue as a good first issue.
    example: /gfi js or /good-first-issue ci-cd

@smoya
Copy link
Member Author

smoya commented Dec 4, 2023

/gfi ci-cd

@asyncapi-bot asyncapi-bot added area/ci-cd Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. good first issue Good for newcomers labels Dec 4, 2023
@smoya smoya changed the title Fix wrong format for Co-authored automerged commits. Fix wrong format for Co-authored automerged commits + pagination Dec 4, 2023
@Gmin2
Copy link

Gmin2 commented Dec 9, 2023

Hey @smoya I have found a way around for this problem "Each co-author line (Co-authored-by: ...) should appear in a new line as the documentation says."
Now for this problem "we should find an alternative to curl + jq or maybe use some bash so we can implement pagination and by pass the limitation of 100 commit results. There are PR's that have more than 100 commits, specially in long-live branches." should we leverage github rest API?

@smoya
Copy link
Member Author

smoya commented Dec 11, 2023

Hey @smoya I have found a way around for this problem "Each co-author line (Co-authored-by: ...) should appear in a new line as the documentation says."

Feel free to open a PR with that fix as soon as you have it 👍

Now for this problem "we should find an alternative to curl + jq or maybe use some bash so we can implement pagination and by pass the limitation of 100 commit results. There are PR's that have more than 100 commits, specially in long-live branches." should we leverage github rest API?

If we don't use github rest API, what do you suggest as an alternative? GraphQL API also have the same limitation (100 results "per page")

@Gmin2 Gmin2 linked a pull request Dec 17, 2023 that will close this issue
@Gmin2
Copy link

Gmin2 commented Jan 4, 2024

can anyone help me with this

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 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;
  }
}

how do i run this within the github action
should i make a seperate js file ?
cc @smoya @KhudaDad414

@smoya
Copy link
Member Author

smoya commented Jan 9, 2024

can anyone help me with this

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 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;
  }
}

how do i run this within the github action should i make a seperate js file ? cc @smoya @KhudaDad414

You will need to run it on your fork or somehow using act. Whatever you use, you will need to modify the action and include something like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci-cd Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants