Skip to content

Commit

Permalink
Merge pull request #7 from TheCleric/master
Browse files Browse the repository at this point in the history
Update with latest enhance-debugging changes
  • Loading branch information
TheCleric authored Aug 25, 2020
2 parents 46182fc + b32d6ac commit 19f9ecd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 34 deletions.
6 changes: 4 additions & 2 deletions __tests__/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import * as core from "@actions/core";
import { readFileSync } from "fs";
import "jest-extended";

// Dump core debug/error to console debug so that --silent works
// Dump core messaging to console so that --silent works
jest.spyOn(core, 'debug').mockImplementation(console.debug);
jest.spyOn(core, 'error').mockImplementation(console.debug);
jest.spyOn(core, 'info').mockImplementation(console.info);
jest.spyOn(core, 'error').mockImplementation(console.error);
jest.spyOn(core, 'warning').mockImplementation(console.warn);

function encodeContent(content: Buffer | ArrayBuffer | SharedArrayBuffer) {
return Buffer.from(content).toString("base64");
Expand Down
17 changes: 3 additions & 14 deletions lib/ConfigEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,24 @@ class ConfigEntry {
getLabel(headRef, baseRef) {
const headMatches = ConfigEntry.getMatches(headRef, this.head, this.headRegExp);
const baseMatches = ConfigEntry.getMatches(baseRef, this.base, this.baseRegExp);
core.debug('*** getLabel ***');
core.debug(JSON.stringify(this));
core.debug('headRef');
core.debug(headRef);
core.debug('headMatches');
core.debug(JSON.stringify(headMatches));
core.debug('baseRef');
core.debug(baseRef);
core.debug('baseMatches');
core.debug(JSON.stringify(baseMatches));
if ((this.head || this.headRegExp) && (this.base || this.baseRegExp)) {
if (headMatches && baseMatches) {
const label = this.getLabelFromMatches(headMatches.concat(baseMatches));
core.debug(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp.toString()}" and "${baseRef}" to "${this.base ? this.base : this.baseRegExp.toString()}". Setting label to "${label}"`);
core.info(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp.toString()}" and "${baseRef}" to "${this.base ? this.base : this.baseRegExp.toString()}". Setting label to "${label}"`);
return label;
}
return undefined;
}
if ((this.head || this.headRegExp) && headMatches) {
const label = this.getLabelFromMatches(headMatches);
core.debug(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp.toString()}". Setting label to "${label}"`);
core.info(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp.toString()}". Setting label to "${label}"`);
return label;
}
if ((this.base || this.baseRegExp) && baseMatches) {
const label = this.getLabelFromMatches(baseMatches);
core.debug(`Matched "${baseRef}" to "${this.base ? this.base : this.baseRegExp.toString()}". Setting label to "${label}"`);
core.info(`Matched "${baseRef}" to "${this.base ? this.base : this.baseRegExp.toString()}". Setting label to "${label}"`);
return label;
}
//core.debug('label', undefined);
return undefined;
}
getLabelFromMatches(matches) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const ConfigEntry_1 = require("./ConfigEntry");
const CONFIG_PATH = ".github";
function getConfig(github, fileName, context) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('getConfig context', context);
try {
const configFile = {
owner: context.repo.owner,
Expand All @@ -44,6 +43,7 @@ function getConfig(github, fileName, context) {
return parseConfig(response.data.content);
}
catch (error) {
core.debug(`getConfig error: ${JSON.stringify(error)}`);
if (error.status === 404) {
return [];
}
Expand Down
18 changes: 3 additions & 15 deletions src/ConfigEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,27 @@ export class ConfigEntry implements ConfigEntryParams {
const headMatches = ConfigEntry.getMatches(headRef, this.head, this.headRegExp);
const baseMatches = ConfigEntry.getMatches(baseRef, this.base, this.baseRegExp);

core.debug('*** getLabel ***');
core.debug(JSON.stringify(this));
core.debug('headRef');
core.debug(headRef);
core.debug('headMatches');
core.debug(JSON.stringify(headMatches));
core.debug('baseRef');
core.debug(baseRef);
core.debug('baseMatches');
core.debug(JSON.stringify(baseMatches));

if ((this.head || this.headRegExp) && (this.base || this.baseRegExp)) {
if (headMatches && baseMatches) {
const label = this.getLabelFromMatches(headMatches.concat(baseMatches));
core.debug(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp!.toString()}" and "${baseRef}" to "${this.base ? this.base : this.baseRegExp!.toString()}". Setting label to "${label}"`);
core.info(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp!.toString()}" and "${baseRef}" to "${this.base ? this.base : this.baseRegExp!.toString()}". Setting label to "${label}"`);
return label;
}
return undefined;
}

if ((this.head || this.headRegExp) && headMatches) {
const label = this.getLabelFromMatches(headMatches);
core.debug(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp!.toString()}". Setting label to "${label}"`);
core.info(`Matched "${headRef}" to "${this.head ? this.head : this.headRegExp!.toString()}". Setting label to "${label}"`);
return label;
}

if ((this.base || this.baseRegExp) && baseMatches) {
const label = this.getLabelFromMatches(baseMatches);
core.debug(`Matched "${baseRef}" to "${this.base ? this.base : this.baseRegExp!.toString()}". Setting label to "${label}"`);
core.info(`Matched "${baseRef}" to "${this.base ? this.base : this.baseRegExp!.toString()}". Setting label to "${label}"`);
return label;
}

//core.debug('label', undefined);
return undefined;
}

Expand Down
3 changes: 1 addition & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { ConfigEntry } from "./ConfigEntry";
const CONFIG_PATH = ".github";

export async function getConfig(github: github.GitHub, fileName: string, context: Context.Context): Promise<ConfigEntry[]> {
// console.log('getConfig context', context);

try {
const configFile = {
owner: context.repo.owner,
Expand All @@ -26,6 +24,7 @@ export async function getConfig(github: github.GitHub, fileName: string, context
}
return parseConfig(response.data.content);
} catch (error) {
core.debug(`getConfig error: ${JSON.stringify(error)}`);
if (error.status === 404) {
return [];
}
Expand Down

0 comments on commit 19f9ecd

Please sign in to comment.