diff --git a/lib/main.js b/lib/main.js index 148ce89..fbcccac 100644 --- a/lib/main.js +++ b/lib/main.js @@ -99,19 +99,18 @@ function run() { } function isFirstIssue(client, sender, curIssueNumber) { return __awaiter(this, void 0, void 0, function* () { - const { status, data: issues } = yield client.rest.issues.listForRepo(Object.assign(Object.assign({}, github.context.repo), { creator: sender, state: 'all' })); - if (status !== 200) { - throw new Error(`Received unexpected API status code ${status}`); - } - if (issues.length === 0) { - return true; + // get the issue details + const { status: getIssueStatus, data: issue } = yield client.rest.issues.get(Object.assign(Object.assign({}, github.context.repo), { issue_number: curIssueNumber })); + if (getIssueStatus !== 200) { + throw new Error(`Received unexpected API status code ${getIssueStatus}`); } - for (const issue of issues) { - if (issue.number < curIssueNumber && !issue.pull_request) { - return false; - } + let query = `repo:${github.context.repo.owner}/${github.context.repo.repo} author:${sender} created:<=${issue.created_at} type:issue`; + const { status: searchStatus, data: searchResults } = yield client.rest.search.issuesAndPullRequests({ q: query }); + if (searchStatus !== 200) { + throw new Error(`Received unexpected API status code ${searchStatus}`); } - return true; + // If current issue is the user's first, there should be exactly one result + return searchResults.total_count === 1; }); } function isFirstOpenedOrMergedPR(client, sender, curPullNumber, closed) { diff --git a/src/main.ts b/src/main.ts index 362dbae..cdc59ce 100644 --- a/src/main.ts +++ b/src/main.ts @@ -96,27 +96,26 @@ async function isFirstIssue( sender: string, curIssueNumber: number ): Promise { - const {status, data: issues} = await client.rest.issues.listForRepo({ + // get the issue details + const {status: getIssueStatus, data: issue} = await client.rest.issues.get({ ...github.context.repo, - creator: sender, - state: 'all' + issue_number: curIssueNumber }); - if (status !== 200) { - throw new Error(`Received unexpected API status code ${status}`); + if (getIssueStatus !== 200) { + throw new Error(`Received unexpected API status code ${getIssueStatus}`); } - if (issues.length === 0) { - return true; - } + let query = `repo:${github.context.repo.owner}/${github.context.repo.repo} author:${sender} created:<=${issue.created_at} type:issue`; - for (const issue of issues) { - if (issue.number < curIssueNumber && !issue.pull_request) { - return false; - } + const {status: searchStatus, data: searchResults} = await client.rest.search.issuesAndPullRequests({ q: query }); + + if (searchStatus !== 200) { + throw new Error(`Received unexpected API status code ${searchStatus}`); } - return true; + // If current issue is the user's first, there should be exactly one result + return searchResults.total_count === 1; } async function isFirstOpenedOrMergedPR(