Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow branchName in reg-notify-github-plugin config #195

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jacobrask
Copy link

What does this change?

Allows setting a branch name in the config, enabling something like

  "reg-notify-github-plugin": {
    "branchName": "$GIT_BRANCH_NAME"
  }

This enables a GitHub workflow where there is no deep clone or re-fetch, and the commit shas are all received from Github context, e.g.

      - name: Compare screenshots
        if: github.event_name == 'pull_request'
        env:
          REG_SUIT_EXPECTED_KEY: ${{ github.event.pull_request.base.sha }}
          REG_SUIT_ACTUAL_KEY: ${{ github.event.pull_request.head.sha }}
       run: ... compare

      - name: Publish results
        if: github.event_name == 'pull_request'
        env:
          REG_SUIT_EXPECTED_KEY: ${{ github.event.pull_request.base.sha }}
          REG_SUIT_ACTUAL_KEY: ${{ github.event.pull_request.head.sha }}
          REG_SUIT_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
       run: ... publish

Allows hard coding a branch name in the config, enabling something like

```
  "reg-notify-github-plugin": {
    "branchName": "$GIT_BRANCH_NAME"
  }
```
@jacobrask
Copy link
Author

I have implemented and tested this in our own repo with the following patch:

--- a/node_modules/reg-notify-github-plugin/lib/github-notifier-plugin.js
+++ b/node_modules/reg-notify-github-plugin/lib/github-notifier-plugin.js
@@ -39,6 +39,9 @@ class GitHubNotifierPlugin {
         else {
             this._apiOpt = config.options;
         }
+        if (config.options.branchName) {
+            this._apiOpt.branchName = config.options.branchName;
+        }
         this._prComment = config.options.prComment !== false;
         this._setCommitStatus = config.options.setCommitStatus !== false;
         this._apiPrefix = config.options.customEndpoint || reg_gh_app_interface_1.getGhAppInfo().endpoint;
@@ -85,10 +88,12 @@ class GitHubNotifierPlugin {
             reqs.push(statusReq);
         }
         if (this._prComment) {
-            if (head.type === "branch" && head.branch) {
-                const prCommentBody = Object.assign({}, this._apiOpt, { branchName: head.branch.name, failedItemsCount, newItemsCount, deletedItemsCount, passedItemsCount });
+            if ((head.type === "branch" && head.branch) || this._apiOpt.branchName) {
+                const prCommentBody = Object.assign({}, this._apiOpt, { failedItemsCount, newItemsCount, deletedItemsCount, passedItemsCount });
                 if (params.reportUrl)
                     prCommentBody.reportUrl = params.reportUrl;
+                if (!prCommentBody.branchName && head.branch)
+                    prCommentBody.branchName = head.branch.name;
                 const commentReq = {
                     uri: `${this._apiPrefix}/api/comment-to-pr`,
                     method: "POST",

but it's a bit difficult to test this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant