From 952ad933016aacab7e35f18cf1a9609b6cf918c1 Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Mon, 14 Sep 2020 23:11:49 +0900 Subject: [PATCH] feat: Add pull_request.user.login --- .github/workflows/label-commenter.yml | 2 +- src/main.ts | 35 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/label-commenter.yml b/.github/workflows/label-commenter.yml index cec0cc7b..0202a33e 100644 --- a/.github/workflows/label-commenter.yml +++ b/.github/workflows/label-commenter.yml @@ -23,7 +23,7 @@ jobs: ref: master - name: Label Commenter - uses: peaceiris/actions-label-commenter@v1.6.0 + uses: peaceiris/actions-label-commenter@v1.6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} # config_file: .github/label-commenter-config.yml diff --git a/src/main.ts b/src/main.ts index 1a4dfb71..df813831 100644 --- a/src/main.ts +++ b/src/main.ts @@ -127,16 +127,33 @@ export async function run(): Promise { } // Render template - const commentBodyView = { - issue: { - user: { - login: (context.payload as any).issue.user.login // eslint-disable-line @typescript-eslint/no-explicit-any - } - }, - sender: { - login: (context.payload as any).sender.login // eslint-disable-line @typescript-eslint/no-explicit-any + const commentBodyView = (() => { + if (eventName === 'issues') { + return { + issue: { + user: { + login: (context.payload as any).issue.user.login // eslint-disable-line @typescript-eslint/no-explicit-any + } + }, + sender: { + login: (context.payload as any).sender.login // eslint-disable-line @typescript-eslint/no-explicit-any + } + }; + } else if (eventName === 'pull_request' || eventName === 'pull_request_target') { + return { + pull_request: { + user: { + login: (context.payload as any).pull_request.user.login // eslint-disable-line @typescript-eslint/no-explicit-any + } + }, + sender: { + login: (context.payload as any).sender.login // eslint-disable-line @typescript-eslint/no-explicit-any + } + }; + } else { + return {}; } - }; + })(); const commentBodyRendered = Mustache.render(commentBody, commentBodyView); // Post comment