Merge pull request #367 from github/simon-engledew/remove-january-warning
Remove date specific pull request warnings
This commit is contained in:
commit
6408d72268
6 changed files with 33 additions and 74 deletions
33
lib/actions-util.js
generated
33
lib/actions-util.js
generated
|
|
@ -141,12 +141,6 @@ function branchesToArray(branches) {
|
||||||
}
|
}
|
||||||
return "**";
|
return "**";
|
||||||
}
|
}
|
||||||
var MissingTriggers;
|
|
||||||
(function (MissingTriggers) {
|
|
||||||
MissingTriggers[MissingTriggers["None"] = 0] = "None";
|
|
||||||
MissingTriggers[MissingTriggers["Push"] = 1] = "Push";
|
|
||||||
MissingTriggers[MissingTriggers["PullRequest"] = 2] = "PullRequest";
|
|
||||||
})(MissingTriggers || (MissingTriggers = {}));
|
|
||||||
function toCodedErrors(errors) {
|
function toCodedErrors(errors) {
|
||||||
return Object.entries(errors).reduce((acc, [key, value]) => {
|
return Object.entries(errors).reduce((acc, [key, value]) => {
|
||||||
acc[key] = { message: value, code: key };
|
acc[key] = { message: value, code: key };
|
||||||
|
|
@ -157,8 +151,6 @@ function toCodedErrors(errors) {
|
||||||
// message to add as a warning annotation to the run
|
// message to add as a warning annotation to the run
|
||||||
exports.WorkflowErrors = toCodedErrors({
|
exports.WorkflowErrors = toCodedErrors({
|
||||||
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
|
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
|
||||||
MissingHooks: `Please specify on.push and on.pull_request hooks so that Code Scanning can compare pull requests against the state of the base branch.`,
|
|
||||||
MissingPullRequestHook: `Please specify an on.pull_request hook so that Code Scanning is explicitly run against pull requests. This will be required to see results on pull requests from January 31 2021.`,
|
|
||||||
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
|
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
|
||||||
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
|
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
|
||||||
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
|
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
|
||||||
|
|
@ -185,27 +177,27 @@ function getWorkflowErrors(doc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let missing = MissingTriggers.None;
|
let missingPush = false;
|
||||||
if (doc.on === undefined) {
|
if (doc.on === undefined) {
|
||||||
// this is not a valid config
|
// this is not a valid config
|
||||||
}
|
}
|
||||||
else if (typeof doc.on === "string") {
|
else if (typeof doc.on === "string") {
|
||||||
if (doc.on === "pull_request") {
|
if (doc.on === "pull_request") {
|
||||||
missing = MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Array.isArray(doc.on)) {
|
else if (Array.isArray(doc.on)) {
|
||||||
const hasPush = doc.on.includes("push");
|
const hasPush = doc.on.includes("push");
|
||||||
const hasPullRequest = doc.on.includes("pull_request");
|
const hasPullRequest = doc.on.includes("pull_request");
|
||||||
if (hasPullRequest && !hasPush) {
|
if (hasPullRequest && !hasPush) {
|
||||||
missing = missing | MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isObject(doc.on)) {
|
else if (isObject(doc.on)) {
|
||||||
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
|
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
|
||||||
const hasPullRequest = Object.prototype.hasOwnProperty.call(doc.on, "pull_request");
|
const hasPullRequest = Object.prototype.hasOwnProperty.call(doc.on, "pull_request");
|
||||||
if (!hasPush && hasPullRequest) {
|
if (!hasPush && hasPullRequest) {
|
||||||
missing = missing | MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
if (hasPush && hasPullRequest) {
|
if (hasPush && hasPullRequest) {
|
||||||
const paths = (_e = doc.on.push) === null || _e === void 0 ? void 0 : _e.paths;
|
const paths = (_e = doc.on.push) === null || _e === void 0 ? void 0 : _e.paths;
|
||||||
|
|
@ -243,21 +235,8 @@ function getWorkflowErrors(doc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
if (missingPush) {
|
||||||
// on is not a known type
|
errors.push(exports.WorkflowErrors.MissingPushHook);
|
||||||
// this workflow is likely malformed
|
|
||||||
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
|
|
||||||
}
|
|
||||||
switch (missing) {
|
|
||||||
case MissingTriggers.PullRequest | MissingTriggers.Push:
|
|
||||||
errors.push(exports.WorkflowErrors.MissingHooks);
|
|
||||||
break;
|
|
||||||
case MissingTriggers.PullRequest:
|
|
||||||
errors.push(exports.WorkflowErrors.MissingPullRequestHook);
|
|
||||||
break;
|
|
||||||
case MissingTriggers.Push:
|
|
||||||
errors.push(exports.WorkflowErrors.MissingPushHook);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
18
lib/actions-util.test.js
generated
18
lib/actions-util.test.js
generated
|
|
@ -167,39 +167,39 @@ ava_1.default("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
}), []));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: 1,
|
jobs: 1,
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: [1],
|
jobs: [1],
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { 1: 1 },
|
jobs: { 1: 1 },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: 1 },
|
jobs: { test: 1 },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: [1] },
|
jobs: { test: [1] },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: { steps: 1 } },
|
jobs: { test: { steps: 1 } },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
|
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: [undefined] },
|
jobs: { test: [undefined] },
|
||||||
}), [actionsutil.WorkflowErrors.MissingHooks]));
|
}), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors(1), []));
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors(1), []));
|
||||||
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
|
||||||
on: {
|
on: {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -232,7 +232,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
actionsutil.getWorkflowErrors({
|
actionsutil.getWorkflowErrors({
|
||||||
on: 1,
|
on: 1,
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -242,7 +242,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: 1,
|
jobs: 1,
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -252,7 +252,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: [1],
|
jobs: [1],
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -262,7 +262,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { 1: 1 },
|
jobs: { 1: 1 },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -272,7 +272,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: 1 },
|
jobs: { test: 1 },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -282,7 +282,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: [1] },
|
jobs: { test: [1] },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -292,7 +292,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: { steps: 1 } },
|
jobs: { test: { steps: 1 } },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -302,7 +302,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
|
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -312,7 +312,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
||||||
on: 1,
|
on: 1,
|
||||||
jobs: { test: [undefined] },
|
jobs: { test: [undefined] },
|
||||||
} as any),
|
} as any),
|
||||||
[actionsutil.WorkflowErrors.MissingHooks]
|
[]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,17 +177,11 @@ function branchesToArray(branches?: string | null | string[]): string[] | "**" {
|
||||||
}
|
}
|
||||||
return "**";
|
return "**";
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MissingTriggers {
|
|
||||||
None = 0,
|
|
||||||
Push = 1,
|
|
||||||
PullRequest = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CodedError {
|
export interface CodedError {
|
||||||
message: string;
|
message: string;
|
||||||
code: string;
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
|
function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
|
||||||
return Object.entries(errors).reduce((acc, [key, value]) => {
|
return Object.entries(errors).reduce((acc, [key, value]) => {
|
||||||
acc[key] = { message: value, code: key };
|
acc[key] = { message: value, code: key };
|
||||||
|
|
@ -199,8 +193,6 @@ function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
|
||||||
// message to add as a warning annotation to the run
|
// message to add as a warning annotation to the run
|
||||||
export const WorkflowErrors = toCodedErrors({
|
export const WorkflowErrors = toCodedErrors({
|
||||||
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
|
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
|
||||||
MissingHooks: `Please specify on.push and on.pull_request hooks so that Code Scanning can compare pull requests against the state of the base branch.`,
|
|
||||||
MissingPullRequestHook: `Please specify an on.pull_request hook so that Code Scanning is explicitly run against pull requests. This will be required to see results on pull requests from January 31 2021.`,
|
|
||||||
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
|
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
|
||||||
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
|
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
|
||||||
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
|
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
|
||||||
|
|
@ -232,19 +224,19 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let missing = MissingTriggers.None;
|
let missingPush = false;
|
||||||
|
|
||||||
if (doc.on === undefined) {
|
if (doc.on === undefined) {
|
||||||
// this is not a valid config
|
// this is not a valid config
|
||||||
} else if (typeof doc.on === "string") {
|
} else if (typeof doc.on === "string") {
|
||||||
if (doc.on === "pull_request") {
|
if (doc.on === "pull_request") {
|
||||||
missing = MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
} else if (Array.isArray(doc.on)) {
|
} else if (Array.isArray(doc.on)) {
|
||||||
const hasPush = doc.on.includes("push");
|
const hasPush = doc.on.includes("push");
|
||||||
const hasPullRequest = doc.on.includes("pull_request");
|
const hasPullRequest = doc.on.includes("pull_request");
|
||||||
if (hasPullRequest && !hasPush) {
|
if (hasPullRequest && !hasPush) {
|
||||||
missing = missing | MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
} else if (isObject(doc.on)) {
|
} else if (isObject(doc.on)) {
|
||||||
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
|
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
|
||||||
|
|
@ -254,7 +246,7 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hasPush && hasPullRequest) {
|
if (!hasPush && hasPullRequest) {
|
||||||
missing = missing | MissingTriggers.Push;
|
missingPush = true;
|
||||||
}
|
}
|
||||||
if (hasPush && hasPullRequest) {
|
if (hasPush && hasPullRequest) {
|
||||||
const paths = doc.on.push?.paths;
|
const paths = doc.on.push?.paths;
|
||||||
|
|
@ -295,22 +287,10 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// on is not a known type
|
|
||||||
// this workflow is likely malformed
|
|
||||||
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (missing) {
|
if (missingPush) {
|
||||||
case MissingTriggers.PullRequest | MissingTriggers.Push:
|
errors.push(WorkflowErrors.MissingPushHook);
|
||||||
errors.push(WorkflowErrors.MissingHooks);
|
|
||||||
break;
|
|
||||||
case MissingTriggers.PullRequest:
|
|
||||||
errors.push(WorkflowErrors.MissingPullRequestHook);
|
|
||||||
break;
|
|
||||||
case MissingTriggers.Push:
|
|
||||||
errors.push(WorkflowErrors.MissingPushHook);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue