Skip to content

Commit

Permalink
Merge branch 'develop' into use-with-keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito authored Jul 18, 2024
2 parents c09d281 + 5083774 commit 10e3236
Show file tree
Hide file tree
Showing 153 changed files with 4,827 additions and 2,855 deletions.
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ body:
label: Error messages or log output
description: Please copy and paste any relevant error messages or log output. This will be automatically formatted, so there is no need for backticks.
render: shell
- type: dropdown
id: stage
attributes:
label: Detection stage
description: At what stage was the bug detected?
options:
- In production (default)
- In beta
- During release testing
- On the development branch
validations:
required: true
- type: input
id: version
attributes:
Expand Down
137 changes: 95 additions & 42 deletions .github/scripts/check-template-and-add-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import {
import { TemplateType, templates } from './shared/template';
import { retrievePullRequest } from './shared/pull-request';

enum RegressionStage {
Development,
Testing,
Beta,
Production
}

const knownBots = ["metamaskbot", "dependabot", "github-actions", "sentry-io"];

main().catch((error: Error): void => {
Expand Down Expand Up @@ -120,23 +127,9 @@ async function main(): Promise<void> {
invalidIssueTemplateLabel,
);

// Extract release version from bug report issue body (if existing)
const releaseVersion = extractReleaseVersionFromBugReportIssueBody(
labelable.body,
);
// Add regression label to the bug report issue
addRegressionLabelToIssue(octokit, labelable);

// Add regression prod label to the bug report issue if release version was found in issue body
if(isReleaseCandidateIssue(labelable)) {
console.log(
`Issue ${labelable?.number} is not a production issue. Regression prod label is not needed.`,
);
} else if (releaseVersion) {
await addRegressionProdLabelToIssue(octokit, releaseVersion, labelable);
} else {
console.log(
`No release version was found in body of bug report issue ${labelable?.number}.`,
);
}
} else {
const errorMessage =
"Issue body does not match any of expected templates ('general-issue.yml' or 'bug-report.yml').\n\nMake sure issue's body includes all section titles.\n\nSections titles are listed here: https://github.com/MetaMask/metamask-extension/blob/develop/.github/scripts/shared/template.ts#L14-L37";
Expand Down Expand Up @@ -215,6 +208,28 @@ function extractTemplateTypeFromBody(body: string): TemplateType {
return TemplateType.None;
}

// This helper function extracts regression stage (Development, Testing, Production) from bug report issue's body.
function extractRegressionStageFromBugReportIssueBody(
body: string,
): RegressionStage | undefined {
const detectionStageRegex = /### Detection stage\s*\n\s*(.*)/i;
const match = body.match(detectionStageRegex);
const extractedAnswer = match ? match[1].trim() : undefined;

switch (extractedAnswer) {
case 'On the development branch':
return RegressionStage.Development;
case 'During release testing':
return RegressionStage.Testing;
case 'In beta':
return RegressionStage.Beta;
case 'In production (default)':
return RegressionStage.Production;
default:
return undefined;
}
}

// This helper function extracts release version from bug report issue's body.
function extractReleaseVersionFromBugReportIssueBody(
body: string,
Expand All @@ -235,49 +250,54 @@ function extractReleaseVersionFromBugReportIssueBody(
return version;
}

// This function adds the correct "regression-prod-x.y.z" label to the issue, and removes other ones
async function addRegressionProdLabelToIssue(
// This function adds the correct regression label to the issue, and removes other ones
async function addRegressionLabelToIssue(
octokit: InstanceType<typeof GitHub>,
releaseVersion: string,
issue: Labelable,
): Promise<void> {
// Craft regression prod label to add
const regressionProdLabel: Label = {
name: `regression-prod-${releaseVersion}`,
color: '5319E7', // violet
description: `Regression bug that was found in production in release ${releaseVersion}`,
};

let regressionProdLabelFound: boolean = false;
const regressionProdLabelsToBeRemoved: {
// Extract regression stage from bug report issue body (if existing)
const regressionStage = extractRegressionStageFromBugReportIssueBody(
issue.body,
);

// Extract release version from bug report issue body (if existing)
const releaseVersion = extractReleaseVersionFromBugReportIssueBody(
issue.body,
);

// Craft regression label to add
const regressionLabel: Label = craftRegressionLabel(regressionStage, releaseVersion);

let regressionLabelFound: boolean = false;
const regressionLabelsToBeRemoved: {
id: string;
name: string;
}[] = [];

// Loop over issue's labels, to see if regression labels are either missing, or to be removed
issue?.labels?.forEach((label) => {
if (label?.name === regressionProdLabel.name) {
regressionProdLabelFound = true;
} else if (label?.name?.startsWith('regression-prod-')) {
regressionProdLabelsToBeRemoved.push(label);
if (label?.name === regressionLabel.name) {
regressionLabelFound = true;
} else if (label?.name?.startsWith('regression-')) {
regressionLabelsToBeRemoved.push(label);
}
});

// Add regression prod label to the issue if missing
if (regressionProdLabelFound) {
if (regressionLabelFound) {
console.log(
`Issue ${issue?.number} already has ${regressionProdLabel.name} label.`,
`Issue ${issue?.number} already has ${regressionLabel.name} label.`,
);
} else {
console.log(
`Add ${regressionProdLabel.name} label to issue ${issue?.number}.`,
`Add ${regressionLabel.name} label to issue ${issue?.number}.`,
);
await addLabelToLabelable(octokit, issue, regressionProdLabel);
await addLabelToLabelable(octokit, issue, regressionLabel);
}

// Remove other regression prod label from the issue
await Promise.all(
regressionProdLabelsToBeRemoved.map((label) => {
regressionLabelsToBeRemoved.map((label) => {
removeLabelFromLabelable(octokit, issue, label?.id);
}),
);
Expand Down Expand Up @@ -309,9 +329,42 @@ async function userBelongsToMetaMaskOrg(
return Boolean(userBelongsToMetaMaskOrgResult?.user?.organization?.id);
}

// This function checks if issue is a release candidate (RC) issue, discovered during release regression testing phase. If so, it means it is not a production issue.
function isReleaseCandidateIssue(
issue: Labelable,
): boolean {
return Boolean(issue.labels.find(label => label.name.startsWith('regression-RC')));
// This function crafts appropriate label, corresponding to regression stage and release version.
function craftRegressionLabel(regressionStage: RegressionStage | undefined, releaseVersion: string | undefined): Label {
switch (regressionStage) {
case RegressionStage.Development:
return {
name: `regression-develop`,
color: '5319E7', // violet
description: `Regression bug that was found on development branch, but not yet present in production`,
};

case RegressionStage.Testing:
return {
name: `regression-RC-${releaseVersion || '*'}`,
color: '744C11', // orange
description: releaseVersion ? `Regression bug that was found in release candidate (RC) for release ${releaseVersion}` : `TODO: Unknown release version. Please replace with correct 'regression-RC-x.y.z' label, where 'x.y.z' is the number of the release where bug was found.`,
};

case RegressionStage.Beta:
return {
name: `regression-beta-${releaseVersion || '*'}`,
color: 'D94A83', // pink
description: releaseVersion ? `Regression bug that was found in beta in release ${releaseVersion}` : `TODO: Unknown release version. Please replace with correct 'regression-beta-x.y.z' label, where 'x.y.z' is the number of the release where bug was found.`,
};

case RegressionStage.Production:
return {
name: `regression-prod-${releaseVersion || '*'}`,
color: '5319E7', // violet
description: releaseVersion ? `Regression bug that was found in production in release ${releaseVersion}` : `TODO: Unknown release version. Please replace with correct 'regression-prod-x.y.z' label, where 'x.y.z' is the number of the release where bug was found.`,
};

default:
return {
name: `regression-*`,
color: 'EDEDED', // grey
description: `TODO: Unknown regression stage. Please replace with correct regression label: 'regression-develop', 'regression-RC-x.y.z', or 'regression-prod-x.y.z' label, where 'x.y.z' is the number of the release where bug was found.`,
};
}
}
Loading

0 comments on commit 10e3236

Please sign in to comment.