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

Fix isFirstIssue() logic #2

Merged
merged 1 commit into from
Apr 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "first-interaction-action",
"version": "1.1.1-zephyr-1",
"version": "1.1.1-zephyr-2",
"description": "An action for greeting first time contributors.",
"main": "lib/main.js",
"scripts": {
Expand Down
25 changes: 12 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,26 @@ async function isFirstIssue(
sender: string,
curIssueNumber: number
): Promise<boolean> {
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(
Expand Down