Skip to content

Commit

Permalink
Merge pull request #52 from getappmap/feat/add-issue-parameter
Browse files Browse the repository at this point in the history
If we pass an issue number to the action use it in the analysis
  • Loading branch information
petecheslock authored Dec 14, 2023
2 parents 2a0b28d + 51164d2 commit f53798f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ Add a step like this to your workflow:
# comment be submitted on any workflow run.
project-summary: true

# Explicitly pass the issue number to the analyze function. This is useful in cases where
# you are triggering this action via a webhook from another service and the action is not aware
# of which Pull Request to comment an analysis report on.
issue-number: 14

# Enable verbose logging of CLI subcommands. You can use the standard GitHub
# Action log level option to control verbosity of this Action itself.
# Default: false
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ inputs:
Enable the project summary report. This feature is also enabled automatically when a pull
request contains the archive-action configuration report.
default: 'false'
issue-number:
description:
Explicitly pass the issue number to the analyze function. This is useful in cases where
you are triggering this action via a webhook from another service and the action is not aware
of which Pull Request to comment an analysis report on.
verbose:
description: Enable verbose logging.
outputs:
Expand Down
16 changes: 15 additions & 1 deletion dist/analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28968,6 +28968,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseIssueNumber = void 0;
const core = __importStar(__nccwpck_require__(2186));
const argparse_1 = __nccwpck_require__(1515);
const action_utils_1 = __nccwpck_require__(1259);
Expand Down Expand Up @@ -28996,6 +28997,7 @@ function runInGitHub() {
const retentionDays = parseInt(core.getInput('retention-days') || '7', 10);
const threadCount = threadCountStr ? parseInt(threadCountStr, 10) : undefined;
const projectSummary = core.getBooleanInput('project-summary');
const issueNumber = parseIssueNumber(core.getInput('issue-number'));
const baseRevision = baseRevisionArg || process.env.GITHUB_BASE_REF;
if (!baseRevision)
throw new Error('base-revision argument must be provided, or GITHUB_BASE_REF must be available from GitHub (https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).');
Expand Down Expand Up @@ -29057,7 +29059,7 @@ function runInGitHub() {
yield projectSummaryReport.comment(octokit, projectSummaryReportResult.reportFile);
}
{
const commenter = new action_utils_1.Commenter(octokit, 'appmap');
const commenter = new action_utils_1.Commenter(octokit, 'appmap', issueNumber);
yield commenter.comment(compareReportResult.reportFile);
}
{
Expand Down Expand Up @@ -29147,6 +29149,18 @@ if (require.main === require.cache[eval('__filename')]) {
else
runLocally();
}
function parseIssueNumber(input) {
// If the input is a number and it's an integer, return it directly
if (typeof input === 'number' && Number.isInteger(input)) {
return input;
}
if (typeof input !== 'string') {
return undefined;
}
const parsed = parseInt(input);
return isNaN(parsed) ? undefined : parsed;
}
exports.parseIssueNumber = parseIssueNumber;


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/analyze/index.js.map

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function runInGitHub(): Promise<void> {
const retentionDays = parseInt(core.getInput('retention-days') || '7', 10);
const threadCount = threadCountStr ? parseInt(threadCountStr, 10) : undefined;
const projectSummary = core.getBooleanInput('project-summary');
const issueNumber = parseIssueNumber(core.getInput('issue-number'));

const baseRevision = baseRevisionArg || process.env.GITHUB_BASE_REF;
if (!baseRevision)
Expand Down Expand Up @@ -116,7 +117,7 @@ async function runInGitHub(): Promise<void> {
}

{
const commenter = new Commenter(octokit, 'appmap');
const commenter = new Commenter(octokit, 'appmap', issueNumber);
await commenter.comment(compareReportResult.reportFile);
}
{
Expand Down Expand Up @@ -206,3 +207,17 @@ if (require.main === module) {
if (process.env.CI) runInGitHub();
else runLocally();
}

export function parseIssueNumber(input: unknown): number | undefined {
// If the input is a number and it's an integer, return it directly
if (typeof input === 'number' && Number.isInteger(input)) {
return input;
}

if (typeof input !== 'string') {
return undefined;
}

const parsed = parseInt(input);
return isNaN(parsed) ? undefined : parsed;
}
40 changes: 40 additions & 0 deletions test/analyze.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { parseIssueNumber } from '../src/analyze';

describe('parseIssueNumber', () => {
it('should return an integer when an integer is provided', () => {
expect(parseIssueNumber(123)).toEqual(123);
});

it('should return an integer when a numeric string is provided', () => {
expect(parseIssueNumber('123')).toEqual(123);
});

it('should return undefined when a non-numeric string is provided', () => {
expect(parseIssueNumber('abc')).toBeUndefined();
});

it('should return undefined when an empty string is provided', () => {
expect(parseIssueNumber('')).toBeUndefined();
});

it('should return undefined when a string with spaces is provided', () => {
expect(parseIssueNumber(' ')).toBeUndefined();
});

it('should return undefined when a null value is provided', () => {
expect(parseIssueNumber(null)).toBeUndefined();
});

it('should return undefined when an undefined value is provided', () => {
expect(parseIssueNumber(undefined)).toBeUndefined();
});

it('should return undefined when a boolean value is provided', () => {
expect(parseIssueNumber(true)).toBeUndefined();
expect(parseIssueNumber(false)).toBeUndefined();
});

it('should return the integer part when a string with a number and letters is provided', () => {
expect(parseIssueNumber('123abc')).toEqual(123);
});
});

0 comments on commit f53798f

Please sign in to comment.