From 0cbed3c512c3e58d4e6dd845de7458bebe0c4142 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Mon, 14 Sep 2020 23:13:43 +0900 Subject: [PATCH] feat: Add pull_request.user.login (#278) --- .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