Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into fix/js-package-textd…
Browse files Browse the repository at this point in the history
…omains
  • Loading branch information
anomiex committed Dec 2, 2024
2 parents b8cad3e + 287f263 commit 70b82bb
Show file tree
Hide file tree
Showing 180 changed files with 1,946 additions and 760 deletions.
8 changes: 8 additions & 0 deletions .github/files/e2e-tests/e2e-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const projects = [
suite: '',
buildGroup: 'jetpack-core',
},
{
project: 'Jetpack post editor',
path: 'projects/plugins/jetpack/tests/e2e',
testArgs: [ 'specs/editor', '--retries=1' ],
targets: [ 'plugins/jetpack', 'packages/publicize' ],
suite: '',
buildGroup: 'jetpack-core',
},
{
project: 'Jetpack sync',
path: 'projects/plugins/jetpack/tests/e2e',
Expand Down
55 changes: 38 additions & 17 deletions pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Board triage: add automated triage for Photon.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Labeling: automatically label changes to the External Media extension.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Significance: patch
Type: changed

Updated package dependencies.
Prompt for labels: update wording.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Slack messaging: when a Slack message cannot be sent to a specific channel, send a message to warn about the issue.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Issue triage: post a comment when an issue lacks labels.
2 changes: 1 addition & 1 deletion projects/github-actions/repo-gardening/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"dependencies": {
"@actions/core": "1.10.1",
"@actions/github": "6.0.0",
"@slack/web-api": "7.7.0",
"compare-versions": "3.6.0",
"glob": "10.4.1",
"moment": "2.29.4",
"node-fetch": "2.6.7",
"openai": "4.56.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert )
}
}

// External Media extension.
const externalMedia = file.match(
/^projects\/plugins\/jetpack\/extensions\/shared\/external-media\//
);
if ( externalMedia !== null ) {
keywords.add( '[Extension] External Media' );
}

// React Dashboard and Boost Admin.
const reactAdmin = file.match(
/^(projects\/plugins\/(crm|boost\/app)\/admin|projects\/plugins\/jetpack\/_inc\/client)\//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function cleanIssueContent( content ) {
*
* @param {WebhookPayloadIssue} payload - Issue event payload.
* @param {GitHub} octokit - Initialized Octokit REST client.
*
* @return {Promise<Array>} Promise resolving to an array of all the labels on the issue after the task is over.
*/
async function aiLabeling( payload, octokit ) {
const { issue, repository } = payload;
Expand All @@ -137,15 +139,15 @@ async function aiLabeling( payload, octokit ) {

if ( ! apiKey ) {
debug( `triage-issues > auto-label: No OpenAI key is provided. Bail.` );
return;
return issueLabels;
}

// If the issue already has [Feature] or [Feature Group] labels, bail.
if ( issueLabels.some( label => label.startsWith( '[Feature' ) ) ) {
debug(
`triage-issues > auto-label: Issue #${ number } already has [Feature] or [Feature Group] labels. Skipping.`
);
return;
return issueLabels;
}

if (
Expand All @@ -159,7 +161,7 @@ async function aiLabeling( payload, octokit ) {
debug(
`triage-issues > auto-label: Issue #${ number } doesn't have enough content. Skipping OpenAI analysis.`
);
return;
return issueLabels;
}

debug(
Expand Down Expand Up @@ -190,11 +192,17 @@ async function aiLabeling( payload, octokit ) {
} );

// During testing, post a comment on the issue with the explanations.
const explanationComment = `**OpenAI suggested the following labels for this issue:**
let explanationComment = `**OpenAI suggested the following labels for this issue:**
${ Object.entries( explanations )
.map( ( [ labelName, explanation ] ) => `- ${ labelName }: ${ explanation }` )
.join( '\n' ) }`;

if ( ownerLogin === 'automattic' ) {
explanationComment += `
If you have feedback about the labels suggested, please let us know in #repo-gardening!`;
}

await octokit.rest.issues.createComment( {
owner: ownerLogin,
repo: name,
Expand All @@ -209,7 +217,12 @@ ${ Object.entries( explanations )
issue_number: number,
labels: [ '[Experiment] AI labels added' ],
} );

// Add the labels we've added to our existing array of labels.
issueLabels.push( ...labels, '[Experiment] AI labels added' );
}
}

return issueLabels;
}
module.exports = aiLabeling;
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export const automatticAssignments = {
},
Boost: {
team: 'Heart of Gold',
labels: [ '[Plugin] Boost' ],
labels: [
'[Plugin] Boost',
'[Boost Feature] Lazy Images',
'[Boost Feature] Image Guide',
'[Boost Feature] Image Size Analysis',
],
slack_id: 'C016BBAFHHS',
board_id: 'https://github.com/orgs/Automattic/projects/548',
},
Expand Down Expand Up @@ -126,6 +131,12 @@ export const automatticAssignments = {
slack_id: 'C02NQ4HMJKV',
board_id: 'https://github.com/orgs/Automattic/projects/657',
},
Photon: {
team: 'Heart of Gold',
labels: [ '[Feature] Photon', '[Boost Feature] Image CDN', '[Package] Image CDN' ],
slack_id: 'C016BBAFHHS',
board_id: 'https://github.com/orgs/Automattic/projects/548',
},
Protect: {
team: 'Scan',
labels: [ '[Plugin] Protect', '[Feature] Protect', '[Package] WAF' ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ const updateBoard = require( './update-board' );

/* global GitHub, WebhookPayloadIssue */

/**
* If we could not add labels via OpenAI, let's add a comment to ask the issue author to add their own labels.
*
* We only want to do this if the author can actually add labels to the issue, i.e. if they're part of the organization.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} ownerLogin - Owner of the repository.
* @param {string} authorLogin - Author of the issue.
* @param {string} repo - Repository name.
* @param {number} issueNumber - Issue number.
*
* @return {Promise<void>} Promise resolving when the comment is added.
*/
async function addCommentAskLabels( octokit, ownerLogin, authorLogin, repo, issueNumber ) {
debug(
`triage-issues > auto-label: Issue #${ issueNumber } created by ${ authorLogin }, lacking label suggestions by OpenAI. Asking the author to add labels.`
);

// Check if issue author is org member
// Result is communicated by status code, and non-successful status codes throw.
// https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
try {
await octokit.rest.orgs.checkMembershipForUser( {
org: ownerLogin,
username: authorLogin,
} );
} catch ( error ) {
debug(
`triage-issues > auto-label: Author ${ authorLogin } is not an org member. Skipping comment.`
);
return;
}

const commentBody = `This issue could use some more labels, to help prioritize and categorize our work. Could you please add at least a \`[Type]\`, a \`[Feature]\`, and a \`[Pri]\` label?
`;

await octokit.rest.issues.createComment( {
owner: ownerLogin,
repo,
body: commentBody,
issue_number: issueNumber,
} );
}

/**
* Automatically add labels to issues, and send Slack notifications.
*
Expand All @@ -24,7 +68,12 @@ const updateBoard = require( './update-board' );
*/
async function triageIssues( payload, octokit ) {
const { action, issue, repository } = payload;
const { number, body, state } = issue;
const {
user: { login: authorLogin },
number,
body,
state,
} = issue;
const { owner, name, full_name } = repository;
const ownerLogin = owner.login;

Expand Down Expand Up @@ -100,7 +149,17 @@ async function triageIssues( payload, octokit ) {
}

// Use OpenAI to automatically add labels to issues.
await aiLabeling( payload, octokit );
const issueLabels = await aiLabeling( payload, octokit );

// At this point, if we still miss a [Type] label, a [Feature] label, or a [Pri] label, ask the author to add it.
const requiredLabelTypes = [ '[Type]', '[Feature', '[Pri]' ];
const missingLabelTypes = requiredLabelTypes.filter(
requiredLabelType => ! issueLabels.some( label => label.startsWith( requiredLabelType ) )
);

if ( missingLabelTypes.length > 0 ) {
await addCommentAskLabels( octokit, ownerLogin, authorLogin, name, number );
}
}

// Triage the issue to a Project board if necessary and possible.
Expand Down
Loading

0 comments on commit 70b82bb

Please sign in to comment.