Skip to content

Commit

Permalink
First attempt at PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Dec 31, 2023
1 parent e0b3f31 commit 3ec0a5f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
20 changes: 20 additions & 0 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140515,6 +140515,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.generateJobSummary = void 0;
const core = __importStar(__nccwpck_require__(42186));
const github = __importStar(__nccwpck_require__(95438));
const summary_1 = __nccwpck_require__(81327);
const params = __importStar(__nccwpck_require__(23885));
const cache_reporting_1 = __nccwpck_require__(66674);
Expand All @@ -140526,6 +140527,7 @@ function generateJobSummary(buildResults, cacheListener) {
core.summary.addRaw(summaryTable);
core.summary.addRaw(cachingReport);
yield core.summary.write();
yield addPRComment(summaryTable);
}
else {
core.info('============================');
Expand All @@ -140537,6 +140539,24 @@ function generateJobSummary(buildResults, cacheListener) {
});
}
exports.generateJobSummary = generateJobSummary;
function addPRComment(content) {
return __awaiter(this, void 0, void 0, function* () {
try {
const github_token = params.getGithubToken();
const context = github.context;
if (context.payload.pull_request == null) {
core.info('Not a PR');
return;
}
const pull_request_number = context.payload.pull_request.number;
const octokit = github.getOctokit(github_token);
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request_number, body: content }));
}
catch (error) {
core.warning(`Failed to generate PR comment: ${String(error)}`);
}
});
}
function renderSummaryTable(results) {
if (results.length === 0) {
return 'No Gradle build results detected.';
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137836,6 +137836,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.generateJobSummary = void 0;
const core = __importStar(__nccwpck_require__(42186));
const github = __importStar(__nccwpck_require__(95438));
const summary_1 = __nccwpck_require__(81327);
const params = __importStar(__nccwpck_require__(23885));
const cache_reporting_1 = __nccwpck_require__(66674);
Expand All @@ -137847,6 +137848,7 @@ function generateJobSummary(buildResults, cacheListener) {
core.summary.addRaw(summaryTable);
core.summary.addRaw(cachingReport);
yield core.summary.write();
yield addPRComment(summaryTable);
}
else {
core.info('============================');
Expand All @@ -137858,6 +137860,24 @@ function generateJobSummary(buildResults, cacheListener) {
});
}
exports.generateJobSummary = generateJobSummary;
function addPRComment(content) {
return __awaiter(this, void 0, void 0, function* () {
try {
const github_token = params.getGithubToken();
const context = github.context;
if (context.payload.pull_request == null) {
core.info('Not a PR');
return;
}
const pull_request_number = context.payload.pull_request.number;
const octokit = github.getOctokit(github_token);
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request_number, body: content }));
}
catch (error) {
core.warning(`Failed to generate PR comment: ${String(error)}`);
}
});
}
function renderSummaryTable(results) {
if (results.length === 0) {
return 'No Gradle build results detected.';
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/job-summary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary'

import * as params from './input-params'
Expand All @@ -13,6 +14,8 @@ export async function generateJobSummary(buildResults: BuildResult[], cacheListe
core.summary.addRaw(summaryTable)
core.summary.addRaw(cachingReport)
await core.summary.write()

await addPRComment(summaryTable)
} else {
core.info('============================')
core.info(summaryTable)
Expand All @@ -22,6 +25,29 @@ export async function generateJobSummary(buildResults: BuildResult[], cacheListe
}
}

async function addPRComment(content: string): Promise<void> {
try {
const github_token = params.getGithubToken()

const context = github.context
if (context.payload.pull_request == null) {
core.info('Not a PR')
return
}

const pull_request_number = context.payload.pull_request.number
const octokit = github.getOctokit(github_token)

await octokit.rest.issues.createComment({
...context.repo,
issue_number: pull_request_number,
body: content
})
} catch (error) {
core.warning(`Failed to generate PR comment: ${String(error)}`)
}
}

function renderSummaryTable(results: BuildResult[]): string {
if (results.length === 0) {
return 'No Gradle build results detected.'
Expand Down

0 comments on commit 3ec0a5f

Please sign in to comment.