Skip to content

Commit

Permalink
Fix output format
Browse files Browse the repository at this point in the history
  • Loading branch information
ncalteen committed Feb 22, 2024
1 parent d0179e2 commit a747f2b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 129 deletions.
142 changes: 66 additions & 76 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ describe('First Interaction', () => {

it('Adds a comment to the first interaction', async () => {
mocktokit.graphql.mockReturnValueOnce({
data: {
repository: {
issues: {
nodes: [
{
number: 1
}
]
}
repository: {
issues: {
nodes: [
{
number: 1
}
]
}
}
})
Expand All @@ -126,18 +124,16 @@ describe('First Interaction', () => {

it('Does not add a comment if there are multiple interactions', async () => {
mocktokit.graphql.mockReturnValueOnce({
data: {
repository: {
issues: {
nodes: [
{
number: 1
},
{
number: 2
}
]
}
repository: {
issues: {
nodes: [
{
number: 1
},
{
number: 2
}
]
}
}
})
Expand Down Expand Up @@ -197,28 +193,26 @@ describe('First Interaction', () => {

it('Adds a comment to the first interaction', async () => {
mocktokit.graphql.mockReturnValueOnce({
data: {
repository: {
pullRequests: {
pageInfo: {
hasNextPage: false,
endCursor: null
repository: {
pullRequests: {
pageInfo: {
hasNextPage: false,
endCursor: null
},
nodes: [
{
number: 1,
author: {
login: 'mona'
}
},
nodes: [
{
number: 1,
author: {
login: 'mona'
}
},
{
number: 2,
author: {
login: 'not-mona'
}
{
number: 2,
author: {
login: 'not-mona'
}
]
}
}
]
}
}
})
Expand All @@ -236,48 +230,44 @@ describe('First Interaction', () => {
it('Does not add a comment if there are multiple interactions', async () => {
mocktokit.graphql
.mockReturnValueOnce({
data: {
repository: {
pullRequests: {
pageInfo: {
hasNextPage: true,
endCursor: 'my-cursor'
repository: {
pullRequests: {
pageInfo: {
hasNextPage: true,
endCursor: 'my-cursor'
},
nodes: [
{
number: 1,
author: {
login: 'mona'
}
},
nodes: [
{
number: 1,
author: {
login: 'mona'
}
},
{
number: 2,
author: {
login: 'not-mona'
}
{
number: 2,
author: {
login: 'not-mona'
}
]
}
}
]
}
}
})
.mockReturnValueOnce({
data: {
repository: {
pullRequests: {
pageInfo: {
hasNextPage: false,
endCursor: null
},
nodes: [
{
number: 3,
author: {
login: 'mona'
}
repository: {
pullRequests: {
pageInfo: {
hasNextPage: false,
endCursor: null
},
nodes: [
{
number: 3,
author: {
login: 'mona'
}
]
}
}
]
}
}
})
Expand Down
10 changes: 5 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

38 changes: 17 additions & 21 deletions dist/src/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export async function isFirstIssue(
// response should include a single issue (the one that triggered this action)
// if it's the actor's first issue.
return (
response.data.repository.issues.nodes.length === 1 &&
response.data.repository.issues.nodes[0].number === issueNumber
response.repository.issues.nodes.length === 1 &&
response.repository.issues.nodes[0].number === issueNumber
)
}

Expand Down Expand Up @@ -193,18 +193,18 @@ export async function isFirstPullRequest(

// Iterate over the current page of PRs, checking for any with a matching
// creator but not a matching number.
for (const pull of response.data.repository.pullRequests.nodes)
for (const pull of response.repository.pullRequests.nodes)
if (pull.author.login === actor && pull.number !== pullNumber) return false

// If there is another page of PRs to check, do so.
if (response.data.repository.pullRequests.pageInfo.hasNextPage)
if (response.repository.pullRequests.pageInfo.hasNextPage)
return await isFirstPullRequest(
client,
owner,
repo,
pullNumber,
actor,
response.data.repository.pullRequests.pageInfo.endCursor
response.repository.pullRequests.pageInfo.endCursor
)

// If there are no more pages to check, this is the actor's first PR.
Expand Down
38 changes: 17 additions & 21 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
/** The expected response type for the GraphQL query to list issues. */
export type IssuesGraphQLResponse = {
data: {
repository: {
issues: {
nodes: {
number: number
title: string
}[]
}
repository: {
issues: {
nodes: {
number: number
title: string
}[]
}
}
}

/** The expected response type for the GraphQL query to list pull requests. */
export type PullRequestsGraphQLResponse = {
data: {
repository: {
pullRequests: {
pageInfo: {
hasNextPage: boolean
endCursor: string
}
nodes: {
number: number
author: {
login: string
}
}[]
repository: {
pullRequests: {
pageInfo: {
hasNextPage: boolean
endCursor: string
}
nodes: {
number: number
author: {
login: string
}
}[]
}
}
}

0 comments on commit a747f2b

Please sign in to comment.