Skip to content

Commit

Permalink
further test pr enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Sep 13, 2024
1 parent e016dc5 commit f0f2e16
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
21 changes: 20 additions & 1 deletion .github/scripts/jira/changeset-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,23 @@ export function extractChangesetFiles(): string[] {
`Changeset to extract issues from: ${parsedChangesetFiles.join(", ")}`
);
return parsedChangesetFiles;
}
}

/**
* Extracts a single changeset file. Intended to be used with https://github.com/dorny/paths-filter with
* the 'csv' output format.
*
* @returns An object with single changeset file.
* @throws {Error} If the required environment variable CHANGESET_FILES is missing.
* @throws {Error} If no changeset file exists.
* @throws {Error} If more than one changeset file exists.
*/
export function extractChangesetFile() {
const changesetFiles = extractChangesetFiles()
if (changesetFiles.length > 1) {
throw new Error(`Found ${changesetFiles.length} changeset files, but only 1 was expected.`)
}
const [changesetFile] = changesetFiles;

return { changesetFile };
}
14 changes: 2 additions & 12 deletions .github/scripts/jira/enforce-jira-issue.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import * as core from "@actions/core";
import { createJiraClient, EMPTY_PREFIX, parseIssueNumberFrom, doesIssueExist, PR_PREFIX } from "./lib";
import { appendIssueNumberToChangesetFile, extractChangesetFiles } from "./changeset-lib";
import { appendIssueNumberToChangesetFile, extractChangesetFile } from "./changeset-lib";

async function main() {
const prTitle = process.env.PR_TITLE;
const commitMessage = process.env.COMMIT_MESSAGE;
const branchName = process.env.BRANCH_NAME;
const dryRun = !!process.env.DRY_RUN;
const changesetFiles = extractChangesetFiles();

if (changesetFiles.length > 1) {
core.setFailed(
`This PR must add only one changeset, but found ${changesetFiles.length}`
);

return
}

const changesetFile = changesetFiles[0]
const { changesetFile } = extractChangesetFile();
const client = createJiraClient();

// Checks for the Jira issue number and exit if it can't find it
Expand Down
18 changes: 4 additions & 14 deletions .github/scripts/jira/enforce-jira-solidity-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@ import jira from "jira.js";
import axios from "axios";
import { join } from "path";
import { createJiraClient, extractJiraIssueNumbersFrom, getJiraEnvVars, doesIssueExist, PR_PREFIX, SOLIDITY_REVIEW_PREFIX } from "./lib";
import { appendIssueNumberToChangesetFile, extractChangesetFiles } from "./changeset-lib";
import { appendIssueNumberToChangesetFile, extractChangesetFile } from "./changeset-lib";

async function main() {
core.info('Started linking PR to a Solidity Review issue')
const solidityReviewTemplateKey = readSolidityReviewTemplateKey()
const changesetFiles = extractChangesetFiles();
const { changesetFile } = extractChangesetFile();

if (changesetFiles.length > 1) {
core.setFailed(
`Solidity Review enforcement only works with 1 changeset per PR, but found ${changesetFiles.length} changesets`
);

return
}

const changesetFile = changesetFiles[0]

const jiraPRIssues = await extractJiraIssueNumbersFrom(PR_PREFIX, changesetFiles)
const jiraPRIssues = await extractJiraIssueNumbersFrom(PR_PREFIX, [changesetFile])
if (jiraPRIssues.length !== 1) {
core.setFailed(
`Solidity Review enforcement only works with 1 JIRA issue per PR, but found ${jiraPRIssues.length} issues in changeset file ${changesetFile}`
Expand All @@ -32,7 +22,7 @@ async function main() {
const jiraPRIssue = jiraPRIssues[0]
const client = createJiraClient();

const jiraSolidityIssues = await extractJiraIssueNumbersFrom(SOLIDITY_REVIEW_PREFIX, changesetFiles)
const jiraSolidityIssues = await extractJiraIssueNumbersFrom(SOLIDITY_REVIEW_PREFIX, [changesetFile])
if (jiraSolidityIssues.length > 0) {
for (const jiraIssue of jiraSolidityIssues) {
const exists = await doesIssueExist(client, jiraIssue, false);
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/jira/update-jira-issue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@actions/core";
import jira from "jira.js";
import { tagsToLabels, createJiraClient, parseIssueNumberFrom, PR_PREFIX } from "./lib";
import { tagsToLabels, createJiraClient, parseIssueNumberFrom, EMPTY_PREFIX } from "./lib";

function updateJiraIssue(
client: jira.Version3Client,
Expand Down Expand Up @@ -43,7 +43,7 @@ async function main() {
const client = createJiraClient();

// Checks for the Jira issue number and exit if it can't find it
const issueNumber = parseIssueNumberFrom(PR_PREFIX, prTitle, commitMessage, branchName);
const issueNumber = parseIssueNumberFrom(EMPTY_PREFIX, prTitle, commitMessage, branchName);
if (!issueNumber) {
const msg =
"No JIRA issue number found in: PR title, commit message, or branch name. Please include the issue ID in one of these.";
Expand Down

0 comments on commit f0f2e16

Please sign in to comment.