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

Add the node_id to the available output #299

Merged
merged 1 commit into from Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -60,6 +60,8 @@ jobs:
body-includes: search string 1
- if: steps.fc1.outputs.comment-id != 620947762
run: exit 1
- if: steps.fc1.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDYyMDk0Nzc2Mg=='
run: exit 1
- if: steps.fc1.outputs.comment-body != 'search string 1'
run: exit 1
- if: steps.fc1.outputs.comment-author != 'retepsnave'
Expand All @@ -73,6 +75,8 @@ jobs:
comment-author: retepsnave
- if: steps.fc2.outputs.comment-id != 620947762
run: exit 1
- if: steps.fc2.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDYyMDk0Nzc2Mg=='
run: exit 1

- name: Find comment by body-includes and author
uses: ./
Expand All @@ -83,6 +87,8 @@ jobs:
body-includes: search string 1
- if: steps.fc3.outputs.comment-id != 620947858
run: exit 1
- if: steps.fc3.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDYyMDk0Nzg1OA=='
run: exit 1

- name: No matching comment found
uses: ./
Expand All @@ -93,6 +99,8 @@ jobs:
body-includes: this string will not be found
- if: steps.fc4.outputs.comment-id != ''
run: exit 1
- if: steps.fc4.outputs.comment-node-id != ''
run: exit 1

- name: Find comment by body-includes (requiring pagination)
uses: ./
Expand All @@ -102,6 +110,8 @@ jobs:
body-includes: search string 2
- if: steps.fc5.outputs.comment-id != 703343658
run: exit 1
- if: steps.fc5.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDcwMzM0MzY1OA=='
run: exit 1

- name: Find comment in merged PR
uses: ./
Expand All @@ -111,6 +121,8 @@ jobs:
body-includes: search string 3
- if: steps.fc6.outputs.comment-id != 703352283
run: exit 1
- if: steps.fc6.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDcwMzM1MjI4Mw=='
run: exit 1

- name: Find the last comment by body-includes and author
uses: ./
Expand All @@ -122,6 +134,8 @@ jobs:
direction: last
- if: steps.fc7.outputs.comment-id != 771260630
run: exit 1
- if: steps.fc7.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDc3MTI2MDYzMA=='
run: exit 1

- name: Find comment by body-regex
uses: ./
Expand All @@ -131,6 +145,8 @@ jobs:
body-regex: '^.*search string 1.*$'
- if: steps.fc8.outputs.comment-id != 620947762
run: exit 1
- if: steps.fc8.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDYyMDk0Nzc2Mg=='
run: exit 1

- name: Find nth comment by body-includes
uses: ./
Expand All @@ -141,6 +157,8 @@ jobs:
nth: 2
- if: steps.fc9.outputs.comment-id != 703343294
run: exit 1
- if: steps.fc9.outputs.comment-node-id != 'MDEyOklzc3VlQ29tbWVudDcwMzM0MzI5NA=='
run: exit 1

package:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down
19 changes: 19 additions & 0 deletions __test__/find.unit.test.ts
Expand Up @@ -16,6 +16,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -37,6 +38,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -60,6 +62,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -81,6 +84,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -104,6 +108,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -125,6 +130,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -148,6 +154,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -169,6 +176,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -190,6 +198,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -213,6 +222,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -234,6 +244,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -255,6 +266,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -276,6 +288,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -299,6 +312,7 @@ describe('findCommentPredicate tests', () => {
},
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
Expand All @@ -313,30 +327,35 @@ describe('findMatchingComment tests', () => {
const testComments = [
{
id: 1,
node_id: 'tornado',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
},
{
id: 2,
node_id: 'poppies',
body: `You've always had the power, my dear. You just had to learn it for yourself.`,
user: {login: 'glinda'},
created_at: '2020-01-01T00:00:00Z'
},
{
id: 3,
node_id: 'rubyslippers',
body: `I'll get you, my pretty, and your little dog too!`,
user: {login: 'wicked-witch'},
created_at: '2020-01-01T00:00:00Z'
},
{
id: 4,
node_id: 'auntieem',
body: `Toto, I've a feeling we're not in Kansas anymore.`,
user: {login: 'dorothy'},
created_at: '2020-01-01T00:00:00Z'
},
{
id: 5,
node_id: 'verybadwizard',
body: `I'll get you, my pretty, and your little dog too!`,
user: {login: 'wicked-witch'},
created_at: '2020-01-01T00:00:00Z'
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -24,6 +24,8 @@ inputs:
outputs:
comment-id:
description: 'The id of the matching comment found.'
comment-node-id:
description: 'The GraphQL node id of the matching comment found.'
comment-body:
description: 'The body of the matching comment found.'
comment-author:
Expand Down
2 changes: 2 additions & 0 deletions dist/index.js
Expand Up @@ -157,12 +157,14 @@ function run() {
const comment = yield (0, find_1.findComment)(inputs);
if (comment) {
core.setOutput('comment-id', comment.id.toString());
core.setOutput('comment-node-id', comment.node_id);
core.setOutput('comment-body', comment.body);
core.setOutput('comment-author', comment.user ? comment.user.login : '');
core.setOutput('comment-created-at', comment.created_at);
}
else {
core.setOutput('comment-id', '');
core.setOutput('comment-node-id', '');
core.setOutput('comment-body', '');
core.setOutput('comment-author', '');
core.setOutput('comment-created-at', '');
Expand Down
1 change: 1 addition & 0 deletions src/find.ts
Expand Up @@ -13,6 +13,7 @@ export interface Inputs {

export interface Comment {
id: number
node_id: string
body?: string
user: {
login: string
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Expand Up @@ -25,11 +25,13 @@ async function run(): Promise<void> {

if (comment) {
core.setOutput('comment-id', comment.id.toString())
core.setOutput('comment-node-id', comment.node_id)
core.setOutput('comment-body', comment.body)
core.setOutput('comment-author', comment.user ? comment.user.login : '')
core.setOutput('comment-created-at', comment.created_at)
} else {
core.setOutput('comment-id', '')
core.setOutput('comment-node-id', '')
core.setOutput('comment-body', '')
core.setOutput('comment-author', '')
core.setOutput('comment-created-at', '')
Expand Down