Skip to content

Commit

Permalink
Add better logging (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Oct 9, 2022
1 parent 4cde604 commit 739831d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 24 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ inputs:
add_original_reviewers:
description: Boolean, if set to true the reviewers of the original PR will also be added to the backport PRs
required: false
default: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
37 changes: 31 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176261,7 +176261,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
/* eslint-disable no-console */
const core = __importStar(__nccwpck_require__(42186));
const github_1 = __nccwpck_require__(95438);
const run_1 = __nccwpck_require__(7764);
Expand All @@ -176283,29 +176282,55 @@ const run_1 = __nccwpck_require__(7764);
},
})
.then((res) => {
core.info(`Backport success: ${res.status}`);
core.setOutput('Result', res);
const failureMessage = (0, run_1.getFailureMessage)(res);
if (failureMessage) {
core.setFailed(failureMessage);
}
})
.catch((error) => {
console.error('An error occurred while backporting', error);
core.error(`Backport failure: ${error.message}`);
core.setFailed(error.message);
});


/***/ }),

/***/ 7764:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getFailureMessage = exports.run = void 0;
const core = __importStar(__nccwpck_require__(42186));
const backport_1 = __nccwpck_require__(76253);
async function run({ context, inputs, }) {
core.info('Initiate backport');
const { payload, repo, runId } = context;
const pullRequest = payload.pull_request;
if (!pullRequest) {
Expand All @@ -176322,14 +176347,14 @@ async function run({ context, inputs, }) {
const reviewers = inputs.addOriginalReviewers && Array.isArray(requestedReviewers)
? requestedReviewers.map((reviewer) => reviewer.login)
: [];
console.log({
core.info(JSON.stringify({
assignees,
branchLabelMapping,
pullNumber,
repo,
repoForkOwner,
reviewers,
});
}));
// support for Github enterprise
const gitHostname = context.serverUrl.replace(/^https{0,1}:\/\//, '');
const result = await (0, backport_1.backportRun)({
Expand All @@ -176351,7 +176376,7 @@ async function run({ context, inputs, }) {
},
exitCodeOnFailure: false,
});
console.log('Result', JSON.stringify(result, null, 2));
core.info(`Result ${JSON.stringify(result, null, 2)}`);
return result;
}
exports.run = run;
Expand Down
35 changes: 31 additions & 4 deletions dist/run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFailureMessage = exports.run = void 0;
const core = __importStar(require("@actions/core"));
const backport_1 = require("backport");
async function run({ context, inputs, }) {
core.info('Initiate backport');
const { payload, repo, runId } = context;
const pullRequest = payload.pull_request;
if (!pullRequest) {
Expand All @@ -19,17 +44,19 @@ async function run({ context, inputs, }) {
const reviewers = inputs.addOriginalReviewers && Array.isArray(requestedReviewers)
? requestedReviewers.map((reviewer) => reviewer.login)
: [];
console.log({
core.info(JSON.stringify({
assignees,
branchLabelMapping,
pullNumber,
repo,
repoForkOwner,
reviewers,
});
}));
// support for Github enterprise
const gitHostname = context.serverUrl.replace(/^https{0,1}:\/\//, '');
const result = await (0, backport_1.backportRun)({
options: {
gitHostname: context.serverUrl.replace(/^https{0,1}:\/\//, ''),
gitHostname,
accessToken: inputs.accessToken,
assignees,
branchLabelMapping,
Expand All @@ -46,7 +73,7 @@ async function run({ context, inputs, }) {
},
exitCodeOnFailure: false,
});
console.log('Result', JSON.stringify(result, null, 2));
core.info(`Result ${JSON.stringify(result, null, 2)}`);
return result;
}
exports.run = run;
Expand Down
3 changes: 3 additions & 0 deletions dist/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const backport = __importStar(require("backport"));
const run_1 = require("./run");
describe('run', () => {
Expand All @@ -31,6 +32,8 @@ describe('run', () => {
.spyOn(backport, 'backportRun')
// @ts-expect-error
.mockResolvedValue('backport return value');
// disable logs
jest.spyOn(core, 'info').mockReturnValue();
await (0, run_1.run)({
inputs: {
accessToken: 'very-secret',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import * as core from '@actions/core';
import { context } from '@actions/github';
import { getFailureMessage, run } from './run';
Expand All @@ -21,13 +20,14 @@ run({
},
})
.then((res) => {
core.info(`Backport success: ${res.status}`);
core.setOutput('Result', res);
const failureMessage = getFailureMessage(res);
if (failureMessage) {
core.setFailed(failureMessage);
}
})
.catch((error) => {
console.error('An error occurred while backporting', error);
core.error(`Backport failure: ${error.message}`);
core.setFailed(error.message);
});
4 changes: 4 additions & 0 deletions src/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core';
import { Context } from '@actions/github/lib/context';
import * as backport from 'backport';
import { getFailureMessage, run } from './run';
Expand All @@ -9,6 +10,9 @@ describe('run', () => {
// @ts-expect-error
.mockResolvedValue('backport return value');

// disable logs
jest.spyOn(core, 'info').mockReturnValue();

await run({
inputs: {
accessToken: 'very-secret',
Expand Down
26 changes: 14 additions & 12 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */
import * as core from '@actions/core';
import { Context } from '@actions/github/lib/context';
import { BackportResponse, backportRun, UnhandledErrorResult } from 'backport';

Expand All @@ -14,6 +14,8 @@ export async function run({
addOriginalReviewers: boolean;
};
}) {
core.info('Initiate backport');

const { payload, repo, runId } = context;
const pullRequest = payload.pull_request;

Expand Down Expand Up @@ -41,18 +43,19 @@ export async function run({
? requestedReviewers.map((reviewer) => reviewer.login)
: [];

console.log({
assignees,
branchLabelMapping,
pullNumber,
repo,
repoForkOwner,
reviewers,
});
core.info(
JSON.stringify({
assignees,
branchLabelMapping,
pullNumber,
repo,
repoForkOwner,
reviewers,
})
);

// support for Github enterprise
const gitHostname = context.serverUrl.replace(/^https{0,1}:\/\//, '');

const result = await backportRun({
options: {
gitHostname,
Expand All @@ -73,8 +76,7 @@ export async function run({
exitCodeOnFailure: false,
});

console.log('Result', JSON.stringify(result, null, 2));

core.info(`Result ${JSON.stringify(result, null, 2)}`);
return result;
}

Expand Down

0 comments on commit 739831d

Please sign in to comment.