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

Reformat the Props Bot comment #21

Merged
merged 18 commits into from
Jan 24, 2024
Merged
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
73 changes: 49 additions & 24 deletions dist/index.js

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

35 changes: 19 additions & 16 deletions src/contribution-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,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 +180,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 +208,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>` );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to obtain the GitHub no-reply email addresses via the WP API you're using, ie in the format [email protected]? This will allow co-authored commits to show up without people needing to associate it with their account. As an example, mine is [email protected]

Copy link
Contributor Author

@desrosj desrosj Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but because our ultimate goal is to give credit in the Credits API, I chose to use the [email protected] format. I also didn't love the idea of hard coding personal emails in the commit messages if someone has that setting turned off. I don't recall if the anonymous format worked even if you had that disabled. I could test if there's a strong preference to use that format instead.

The other thought I had was for consistency with how committers are attributed credit from the WordPress/wordpress-develop mirror. When a contributor is granted commit access, they are told to add the @git.wordpress.org format to their account, as that's the email given to the commit author. A "pie in the sky" idea that I'll investigate once we get this initial round settled is to include Co-Authored-By trailers for everyone that receives Props in an SVN commit. My thinking there is that the same format as the committer would make sense.

By including unlinked contributors in the commit message, though, we can easily extract their GH slug from the list and look in the .org database for any contributors that have connected their account since any of their contributions were merged.

There's some weirdness to detail around those emails as noted on that page:

If you created your account on GitHub.com after July 18, 2017, your noreply email address for GitHub is an ID number and your username in the form of [email protected]. If you created your account on GitHub.com prior to July 18, 2017, and enabled Keep my email address private prior to that date, your noreply email address from GitHub is [email protected].
In my research from a year or so ago, I couldn't find a way to figure out which format a specific user has. But in recent testing, I found that both formats worked, regardless of the format it tells you you have.

Another layer to that is on the Change your username page:

If you've been using a GitHub-provided private commit email address, whether or not your commit history will be retained after an account rename depends on the format of the email address. Git commits that are associated with your GitHub-provided noreply email address won't be attributed to your new username and won't appear in your contributions graph, unless your noreply email address is in the form of [email protected]. Older versions of the noreply email address that do not contain a numeric ID will not be associated with your GitHub account after changing your username.

So we'd always need to use the ID+USERNAME format just in case someone changes their username. On the other hand, WP.org usernames cannot be changed.

Sorry for the brain dump, but this was a good chance to document some of my thinking/findings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the goal here is to improve the breadth of folks properly credited from GitHub repos back to WordPress core major releases and to streamline the major release credits gathering process, the approach that @desrosj has here makes sense. If the goal was to ensure all GitHub users were properly credited on PRs, then using the format @peterwilsoncc noted would likely be the best approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been thinking about this the last few days.

I think I do prefer using all .org usernames, but it could be reasonable to use the GH format email for any contributor that's not linked to a .org one.

We can still parse out their GH user and look them up in the .org API, and they'd receive attribution on GH from their anonymous email. But that also removes some of the incentive to connect their account in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@desrosj Does the WP.org integration add [email protected] to a users profile when they link their accounts or is that a step the contributor would need to do to get recognition on GitHub?

Copy link
Contributor Author

@desrosj desrosj Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, they will need to add it manually. I plan to include this in the announcement post, and the documentation. Based on this comment , though, it doesn't seem that our authentication request currently allows us to modify your profile at all. We'd need to add that to the request, and contributors with pre-existing connections would need to re-approve the connection with the new permissions.

I was talking this through with @dd32 last night. Wanted to document our discussion. At first he did not like using @git.wp.org emails, but after some discussion, this was how he summarized his thoughts:

  • On a GitHub-first repo, it makes sense to use @…github.com emails
  • On a SVN repo, it makes sense to use username
  • On a SVN -> Git sync, it makes sense to append Co-Authored-by: …@git.wordpress.org (But who knows if we wanna do that)
  • On a SVN -> Git -> GitHub sync, We can’t modify the commit message of ^ so meh, i guess it makes sense to use @git.w.org
  • Because of ^, it makes sense that on a GitHub-First repo, we could just use @git.w.org for consistency.

It's worth noting that in that list, there are currently no SVN -> Git syncs that do not make it over to GitHub.

Some other takeaways from our discussion:

  • Even though we're heavily using GitHub at this point, there's always a non-0 chance that as a project we decide to use something other than GitHub (ie. GitLab). If this does happen, then the ID+username@github emails would be out of place. We could likely add a way for the tool to support these, but using wp.org ones would be somewhat tool-agnostic.
  • There's currently no ability to validate that you own the @git.wp.org email that represents you. Adding the ability to verify this through email will likely be appropriate to avoid any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone and created #28 for changing the unlinked contributor list to use GH emails. I think that makes sense, but figured it would be good to tackle separately.

})
.filter((el) => el)
.join("\n")
);
})
.join("\n\n");
.filter((el) => el);
});

core.debug( contributorLists );

return contributorLists;
}

/**
Expand Down
38 changes: 30 additions & 8 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,17 @@ 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 );

let prNumber = context.payload?.pull_request?.number;
if ( 'issue_comment' === context.eventName ) {
prNumber = context.payload?.issue?.number;
Expand All @@ -133,23 +136,42 @@ 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 = "The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the `props-bot` label.\n\n";

if ( contributorsList['unlinked'].length > 0 ) {
commentMessage += "## Unlinked Accounts\n\n" +
"The following contributors have not linked their GitHub and WordPress.org accounts: @" + contributorsList['unlinked'].join(', @') + ".\n\n" +
"Contributors, please [read how to link your accounts](https://make.wordpress.org/core/2020/03/19/associating-github-accounts-with-wordpress-org-profiles/) to ensure your work is properly credited in WordPress releases.\n\n";
}

commentMessage += "## Core SVN\n\n" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@desrosj, would it be possible to make this configurable? While Core SVN makes perfect sense in WordPress develop, the GitHub Merge isn't that useful. Then, when contributing to Gutenberg, it exactly the other way around. So while the default could be as is, what if you could pass the setting when defining the GitHub workflow?

svnProps: true
gitCoAuthored: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make an issue for this on the @WordPress/props-bot-core repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleasure: #38 :)

"If you're a Core Committer, use this list when committing to `wordpress-develop` in SVN:\n" +
"```\n" +
contributorsList +
"\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";

if ( contributorsList['unlinked'].length > 0 ) {
commentMessage += "Unlinked contributors: " + contributorsList['unlinked'].join(', ') + ".\n\n";
}

commentMessage += contributorsList['coAuthored'].join("\n") +
"\n```\n\n" +
"**To understand the WordPress project's expectations around crediting contributors, please [review the core handbook](https://make.wordpress.org/core/handbook/).**\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added ticket #29 to replace this link, but it's not a blocker.


const comment = {
...commentInfo,
body: commentMessage + "\n\n<sub>props-bot-action</sub>",
body: commentMessage,
};

const comments = (await this.octokit.rest.issues.listComments(commentInfo))
.data;
for (const currentComment of comments) {
if (
currentComment.user.type === "Bot" &&
/<sub>[\s\n]*props-bot-action/.test(currentComment.body)
currentComment.body.includes( 'The following accounts have interacted with this PR and/or linked issues.' )
) {
commentId = currentComment.id;
break;
Expand Down