Skip to content

Commit

Permalink
Reformat the Props Bot comment.
Browse files Browse the repository at this point in the history
This reformats the comment left by the bot in a few ways:
- The SVN `Props:` style attribution line is now included as an option in the comment.
- The headers for the `Co-Authored-By` style comment are removed.
- The Unlinked Contributors are now listed before the `Co-Authored-By` ones.
- There is significantly more context in the comment around what's going on, how to appropriately use the information in the comment, or learn more.
- Unlinked contributors are now pinged as part of the comment with a request to connect their accounts.
  • Loading branch information
desrosj committed Jan 18, 2024
1 parent fc5a854 commit dbd7ca5
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 44 deletions.
80 changes: 58 additions & 22 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions src/contribution-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export async function getContributorsList() {
.forEach((comment) => contributors.commenters.add(comment.author.login));

core.debug('Commenters:');
core.debug(contributors);
core.debug(contributors.commenters);

// Process reporters and commenters for linked issues.
Expand Down Expand Up @@ -162,8 +163,13 @@ export async function getContributorsList() {
core.debug(githubUsers);
}

// List to return from the function.
const contributorLists = [];
contributorLists['github'] = [];

// Collect WordPress.org usernames
const wpOrgData = await getWPOrgData(githubUsers);
contributorLists['svn'] = [];

core.debug('WordPress.org raw data:');
core.debug(wpOrgData);
Expand All @@ -175,28 +181,25 @@ export async function getContributorsList() {
wpOrgData[contributor] !== false
) {
userData[contributor].dotOrg = wpOrgData[contributor].slug;
contributorLists['svn'].push(wpOrgData[contributor].slug);
}
});

return contributorTypes
contributorLists['coAuthored'] = [];
contributorLists['unlinked'] = [];

contributorTypes
.map((priority) => {
// Skip an empty set of contributors.
if (contributors[priority].length === 0) {
return [];
}

// Add a header for each section.
const header =
"# " + priority.replace(/^./, (char) => char.toUpperCase()) + "\n";

// Generate each props entry, and join them into a single string.
return (
header +
[...contributors[priority]]
.map((username) => {
if ('unlinked' == priority) {
core.debug( 'Unlinked contributor: ' + username );
return `Unlinked contributor: ${username}`;
return;
}

const { dotOrg } = userData[username];
Expand All @@ -206,17 +209,18 @@ export async function getContributorsList() {
"dotOrg"
)
) {
contributors.unlinked.add(username);
contributorLists['unlinked'].push(username);
return;
}

return `Co-Authored-By: ${username} <${dotOrg}@git.wordpress.org>`;
return contributorLists['coAuthored'].push( `Co-Authored-By: ${username} <${dotOrg}@git.wordpress.org>` );
})
.filter((el) => el)
.join("\n")
);
})
.join("\n\n");
.filter((el) => el);
});

core.debug( contributorLists );

return contributorLists;
}

/**
Expand Down
44 changes: 38 additions & 6 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ export default class GitHub {
* - If a comment already exists, it will be updated.
*
* @param {Object} context The GitHub context.
* @param {string} contributorsList The list of contributors.
* @param {array} contributorsList The list of contributors.
*/
async commentProps({ context, contributorsList }) {
if (!contributorsList) {
core.info("No contributors list provided.");
core.info("No contributors were provided.");
return;
}

core.debug( "Contributor list received:" );
core.debug( contributorsList );
core.debug( contributorsList.svn );
console.debug( contributorsList );

let prNumber = context.payload?.pull_request?.number;
if ( 'issue_comment' === context.eventName ) {
prNumber = context.payload?.issue?.number;
Expand All @@ -133,11 +138,38 @@ export default class GitHub {
issue_number: prNumber,
};

const commentMessage =
"Here is a list of everyone that appears to have contributed to this PR and any linked issues:\n\n" +
let commentMessage = "Hello contributors!\n\n" +
"I've collected a list of people who have interacted in some way with this pull request or any linked issues. I'll continue to update this list as activity occurs.\n\n";

if ( contributorsList['unlinked'].length > 0 ) {
commentMessage += "## Unlinked Accounts\n\n" +
"It appears there are some GitHub contributors participating here that have not linked their WordPress.org accounts.\n\n" +
"@" + contributorsList['unlinked'].join(', @') + ": Thank you for your contribution to this repository!\n\n" +
"The WordPress project gives contributors attribution through the [WordPress.org Credits API](https://api.wordpress.org/core/credits/1.1/). However, attribution can only be given to a WordPress.org account." +
"Please take a moment to connect your GitHub and WordPress.org accounts when you have a moment so that your contribution can be properly recognized. You'll find [step by step instructions on the Making WordPress Core blog](https://make.wordpress.org/core/2020/03/19/associating-github-accounts-with-wordpress-org-profiles/).\n\n";
}

commentMessage += "**Reminder: giving props is mandatory for any repository under the WordPress organization if you are a project maintainer or committer**.\n\n" +
"Here is a contributor list formatted in a few ways.:\n\n" +
"## Core SVN\n\n" +
"If you're a Core Committer, use this list when committing to `wordpress-develop` in SVN:\n" +
"```\n" +
"Props: " + contributorsList['svn'].join(', ') + "." +
"\n```\n\n" +
"## GitHub Merge commits\n\n" +
"If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.\n\n" +
"```\n" +
contributorsList +
"\n```";
"Unlinked contributors: " + contributorsList['unlinked'].join(', ') + ".\n\n" +
contributorsList['coAuthored'].join("\n") +
"\n```\n\n" +
"**Important notes**:" +
"- The list of `Co-Authored-By:` trailers must be preceded by a blank line.\n" +
"- Usernames must not start with an `@`.\n" +
"- Nothing can come after the `Co-Authored-By:` trailers.\n" +
"- Please include the list of unlinked contributors. If they do connect their GitHub and WordPress.org accounts in the future, this contribution can be credited to them later.\n" +
"- Merging contributors should remove themselves from the list. As the merging contributor, props will be given for being the author of the merge commit.\n" +
"- As always, please manually review this list. [Give props liberally](https://make.wordpress.org/core/handbook/best-practices/commit-messages/#props), but remove anyone users who spammed or did not contribute positively.\n" +
"- If you're unsure, please ask in the [#core-committers channel in Slack](https://wordpress.slack.com/archives/C18723MQ8).\n";

const comment = {
...commentInfo,
Expand Down

0 comments on commit dbd7ca5

Please sign in to comment.