From a605c9df34d8986074fd6a09a310fe6ed049453f Mon Sep 17 00:00:00 2001 From: Jacob Rask Date: Sun, 21 Jun 2020 20:51:10 +0200 Subject: [PATCH 1/3] Allow branchName in reg-notify-github-plugin config Allows hard coding a branch name in the config, enabling something like ``` "reg-notify-github-plugin": { "branchName": "$GIT_BRANCH_NAME" } ``` --- .../reg-notify-github-plugin/src/github-notifier-plugin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts index 52dfa918..6e58b5c4 100644 --- a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts +++ b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts @@ -19,6 +19,7 @@ export interface GitHubPluginOption { installationId?: string; owner?: string; repository?: string; + branchName?: string; prComment?: boolean; setCommitStatus?: boolean; customEndpoint?: string; @@ -128,12 +129,12 @@ export class GitHubNotifierPlugin implements NotifierPlugin } if (this._prComment) { - if (head.type === "branch" && head.branch) { + if (head.type === "branch" && (head.branch || this._apiOpt.branchName)) { const prCommentBody: CommentToPrBody = { ...this._apiOpt, - branchName: head.branch.name, failedItemsCount, newItemsCount, deletedItemsCount, passedItemsCount, }; + if (!prCommentBody.branchName && head.branch) prCommentBody.branchName = head.branch.name; if (params.reportUrl) prCommentBody.reportUrl = params.reportUrl; const commentReq: rp.OptionsWithUri = { uri: `${this._apiPrefix}/api/comment-to-pr`, From f9c9dc5539223d36dd732c8b7a02a99b27b6c9c4 Mon Sep 17 00:00:00 2001 From: Jacob Rask Date: Sun, 21 Jun 2020 21:37:44 +0200 Subject: [PATCH 2/3] Add branchName to apiOpt --- .../reg-notify-github-plugin/src/github-notifier-plugin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts index 6e58b5c4..c1c0428c 100644 --- a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts +++ b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts @@ -75,7 +75,10 @@ export class GitHubNotifierPlugin implements NotifierPlugin if (config.options.clientId) { this._apiOpt = this._decodeClientId(config.options.clientId); } else { - this._apiOpt = (config.options as BaseEventBody); + this._apiOpt = (config.options || {} as BaseEventBody); + } + if (config.options.branchName) { + (this._apiOpt as any).branchName = config.options.branchName; } this._prComment = config.options.prComment !== false; this._setCommitStatus = config.options.setCommitStatus !== false; From f9ef7410dff4cc3db2f6528c6c4e811d373236c3 Mon Sep 17 00:00:00 2001 From: Jacob Rask Date: Sun, 21 Jun 2020 21:38:42 +0200 Subject: [PATCH 3/3] Allow head.type to not be branch if branchName is specified --- packages/reg-notify-github-plugin/src/github-notifier-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts index c1c0428c..0faea13c 100644 --- a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts +++ b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts @@ -132,7 +132,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin } if (this._prComment) { - if (head.type === "branch" && (head.branch || this._apiOpt.branchName)) { + if ((head.type === "branch" && head.branch) || this._apiOpt.branchName) { const prCommentBody: CommentToPrBody = { ...this._apiOpt, failedItemsCount, newItemsCount, deletedItemsCount, passedItemsCount,