`clear-pr-merge-commit-message` - Clear redundant co-authors by agriyakhetarpal · Pull Request #9340 · refined-github/refined-github · GitHub
Skip to content
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
4 changes: 3 additions & 1 deletion source/features/clear-pr-merge-commit-message.tsx
8 changes: 7 additions & 1 deletion source/github-helpers/get-comment-author.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {$closest, $closestOptional} from 'select-dom';

/**
Given any element in a comment, returns the comment’s author

Expand Down Expand Up @@ -37,7 +38,12 @@ export default function getCommentAuthor(anyElementInsideComment: Element): stri
.alt // Occasionally ends with `[bot]`
.replace(/^@/, ''); // May or may not be present

if (!name.endsWith('[bot]') && $closestOptional('[href^="https://github.com/apps/"]', avatar)) {
const appLink = $closestOptional([
'a[href^="/apps/"]',
'a[href^="https://github.com/apps/"]',
], avatar);

if (!name.endsWith('[bot]') && appLink) {
// Example: https://github.com/webpack/webpack/pull/15926#issuecomment-1170670173
return name + '[bot]';
}
Expand Down
15 changes: 10 additions & 5 deletions source/github-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import compareVersions from 'tiny-version-compare';
import type {RequireAtLeastOne} from 'type-fest';

import {is} from '../helpers/css-selectors.js';
import getCommentAuthor from './get-comment-author.js';
import {branchSelector} from './selectors.js';

// Re-export for convenience
Expand Down Expand Up @@ -210,11 +211,15 @@ export function scrollIntoViewIfNeeded(element: Element): void {
(element.scrollIntoViewIfNeeded ?? element.scrollIntoView).call(element);
}

function getConversationAuthor(): string | undefined {
return $optional([
'.js-command-palette-pull-body .author', // PR conversation
'[data-testid="issue-body-header-author"]', // Issue conversation
])?.textContent;
Comment thread
fregante marked this conversation as resolved.
export function getConversationBody(): Element {
return $([
'.react-issue-body', // Issues
'.js-command-palette-pull-body', // PRs
Comment thread
fregante marked this conversation as resolved.
]);
}

export function getConversationAuthor(): string {
return getCommentAuthor(getConversationBody());
}

export function isOwnConversation(): boolean {
Expand Down
64 changes: 64 additions & 0 deletions source/helpers/clean-commit-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,70 @@ test('cleanCommitMessage', () => {
'Should preserve both co-authored-by and signed-off-by',
);

assert.isEmpty(
cleanCommitMessage(
`
Some stuff happened
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
`,
false,
['dependabot[bot]'],
),
'Should drop co-author whose privacy email matches the PR author',
);

assert.equal(
cleanCommitMessage(
`
Some stuff happened
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
${coauthors[2]}
`,
false,
['dependabot[bot]'],
),
coauthors[2],
'Should drop only the matching co-author, and keep others',
);

assert.equal(
cleanCommitMessage(
`
Some stuff happened
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
`,
false,
['someone-else'],
),
'Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>',
'Should keep co-author when privacy email username does not match PR author',
);

assert.equal(
cleanCommitMessage(
`
Some stuff happened
${coauthors[0]}
`,
false,
['Me'],
),
coauthors[0],
'Should keep co-author when email is not a GitHub privacy email, even if the name matches PR author',
);

assert.isEmpty(
cleanCommitMessage(
`
Some stuff happened
Co-authored-by: someuser <someuser@users.noreply.github.com>
`,
false,
['someuser'],
),
'Should drop co-author with legacy privacy email without numeric prefix prior to July 18, 2017',
);
Comment thread
fregante marked this conversation as resolved.

assert.isEmpty(
cleanCommitMessage(`
Fixes #1345
Expand Down
14 changes: 12 additions & 2 deletions source/helpers/clean-commit-message.ts
Loading