From 505676727409c00e97cdfb0d06b67e387eec5404 Mon Sep 17 00:00:00 2001 From: Matteo Casonato Date: Fri, 16 Dec 2022 15:48:18 +0100 Subject: [PATCH 1/3] Add "comment-date" as output --- __test__/find.unit.test.ts | 41 +++++++++++++++++++++++++------------- src/find.ts | 1 + src/main.ts | 2 ++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/__test__/find.unit.test.ts b/__test__/find.unit.test.ts index 803ce94..381370a 100644 --- a/__test__/find.unit.test.ts +++ b/__test__/find.unit.test.ts @@ -1,4 +1,4 @@ -import {findCommentPredicate} from '../lib/find' +import {findCommentPredicate} from '../src/find' describe('find comment tests', () => { test('find by bodyIncludes', async () => { @@ -16,7 +16,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) @@ -35,7 +36,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -56,7 +58,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) @@ -75,7 +78,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -96,7 +100,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) @@ -115,7 +120,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -136,7 +142,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) @@ -155,7 +162,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -174,7 +182,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -195,7 +204,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) @@ -214,7 +224,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -233,7 +244,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(false) @@ -254,7 +266,8 @@ describe('find comment tests', () => { { id: 1, body: `Toto, I've a feeling we're not in Kansas anymore.`, - user: {login: 'dorothy'} + user: {login: 'dorothy'}, + created_at: '2020-01-01T00:00:00Z' } ) ).toEqual(true) diff --git a/src/find.ts b/src/find.ts index 62bf472..5c28771 100644 --- a/src/find.ts +++ b/src/find.ts @@ -16,6 +16,7 @@ export interface Comment { user: { login: string } | null + created_at: string } export function findCommentPredicate( diff --git a/src/main.ts b/src/main.ts index d0be045..1e82c33 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,10 +26,12 @@ async function run(): Promise { core.setOutput('comment-id', comment.id.toString()) core.setOutput('comment-body', comment.body) core.setOutput('comment-author', comment.user ? comment.user.login : '') + core.setOutput('comment-date', comment.created_at) } else { core.setOutput('comment-id', '') core.setOutput('comment-body', '') core.setOutput('comment-author', '') + core.setOutput('comment-date', '') } } catch (error) { core.debug(inspect(error)) From d225f101d1c1b3beda1a2425212eb1d2fdf3674c Mon Sep 17 00:00:00 2001 From: Matteo Casonato Date: Fri, 16 Dec 2022 16:35:52 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a89572..5d93c9c 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ The action will output the comment ID of the comment matching the search criteri #### Outputs -The `comment-id`, `comment-body` and `comment-author` of the matching comment found will be output for use in later steps. +The `comment-id`, `comment-body`, `comment-author` and `comment-date` of the matching comment found will be output for use in later steps. They will be empty strings if no matching comment was found. Note that in order to read the step outputs the action step must have an id. From ca3afa4f3ca65a8d05493767f759fb17d975de50 Mon Sep 17 00:00:00 2001 From: Matteo Casonato Date: Mon, 19 Dec 2022 11:48:52 +0100 Subject: [PATCH 3/3] comment-date -> comment-created-at --- README.md | 3 ++- src/main.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d93c9c..38e84aa 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ The action will output the comment ID of the comment matching the search criteri #### Outputs -The `comment-id`, `comment-body`, `comment-author` and `comment-date` of the matching comment found will be output for use in later steps. +The `comment-id`, `comment-body`, `comment-author` and `comment-created-at` of the matching comment found will be output for use in later steps. They will be empty strings if no matching comment was found. Note that in order to read the step outputs the action step must have an id. @@ -97,6 +97,7 @@ e.g. If `comment-id` is an empty string `steps.fc.outputs.comment-id == 0` evalu echo ${{ steps.fc.outputs.comment-id }} echo ${{ steps.fc.outputs.comment-body }} echo ${{ steps.fc.outputs.comment-author }} + echo ${{ steps.fc.outputs.comment-created-at }} ``` ### Accessing issues and pull requests in other repositories diff --git a/src/main.ts b/src/main.ts index 1e82c33..71091e5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,12 +26,12 @@ async function run(): Promise { core.setOutput('comment-id', comment.id.toString()) core.setOutput('comment-body', comment.body) core.setOutput('comment-author', comment.user ? comment.user.login : '') - core.setOutput('comment-date', comment.created_at) + core.setOutput('comment-created-at', comment.created_at) } else { core.setOutput('comment-id', '') core.setOutput('comment-body', '') core.setOutput('comment-author', '') - core.setOutput('comment-date', '') + core.setOutput('comment-created-at', '') } } catch (error) { core.debug(inspect(error))