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: close assigned issue logic #1157

Closed

Conversation

Ekep-Obasi
Copy link

@Ekep-Obasi Ekep-Obasi commented Mar 27, 2024

closes: #23

Solution

I realized that the existing logic for closing assigned issues works correctly, but the logic for updating issue always reopens the issue again

        if (
          devpoolIssue.title !== projectIssue.title ||
          devpoolIssue.state !== projectIssue.state || // <-- since the states are different, if block runs
          (!isDevpoolUnavailableLabel && projectIssue.assignee?.login) ||
          (isDevpoolUnavailableLabel && !projectIssue.assignee?.login) ||
          devpoolIssue.body !== projectIssue.html_url ||
          devpoolIssueLabelsStringified !== projectIssueLabelsStringified
        ) {
          await octokit.rest.issues.update({
            owner: DEVPOOL_OWNER_NAME,
            repo: DEVPOOL_REPO_NAME,
            issue_number: devpoolIssue.number,
            title: projectIssue.title,
            body,
            state: projectIssue.state as "open" | "closed", // <--- projectIssue state is set back to "open"
            labels: getDevpoolIssueLabels(projectIssue, projectUrl),
          });
          console.log(`Updated: ${devpoolIssue.html_url} (${projectIssue.html_url})`);
        } else {
          console.log(`No updates: ${devpoolIssue.html_url} (${projectIssue.html_url})`);
        }

You can see this behaviour on this issue or on the screenshot below

evidence

Change

  • refactored the logic that updates issue
// reopen issue only if it doesn't have the `Unavaliable` label 
state: !isDevpoolUnavailableLabel ? (projectIssue.state as "open" | "closed") : "closed",
  • added tests to assert that current functionality (closing of assigned issues) works properly and test are passing locally

work ubi test

- updated devpool issue logic
- wrote tests to confirm that existing logic works well
@Ekep-Obasi Ekep-Obasi marked this pull request as draft March 27, 2024 12:20
@Ekep-Obasi Ekep-Obasi marked this pull request as ready for review March 27, 2024 12:22
Copy link
Member

@rndquu rndquu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue persists

Current behaviour when project issue is assigned and devpool issue is open:

  • 1st index.ts run closes devpool issue
  • 2nd index.ts run opens devpool issue
  • 3rd (and all other) index.ts run closes devpool issue

@gentlementlegen
Copy link
Member

After locally testing, the test test fails with the following state

Error: expect(received).toMatchObject(expected)

- Expected  - 3
+ Received  + 9

@@ -22,11 +22,11 @@
        "subscriptions_url": "",
        "type": "",
        "url": "",
      },
      "author_association": "NONE",
-     "body": "body",
+     "body": "https://github.com/ubiquity/test-repo/issues/1",
      "closed_at": null,
      "comments": 0,
      "comments_url": "",
      "created_at": "",
      "events_url": "",
@@ -35,23 +35,29 @@
      "labels": Array [
        Object {
          "name": "Pricing: 200 USD",
        },
        Object {
-         "name": "Time: 1h",
+         "name": "Partner: ubiquity/test-repo",
        },
        Object {
          "name": "id: 1",
+       },
+       Object {
+         "name": "Unavailable",
        },
+       Object {
+         "name": "Time: 1h",
+       },
      ],
      "labels_url": "",
      "locked": false,
      "milestone": null,
      "node_id": "1",
      "number": 1,
      "repository_url": "https://github.com/ubiquity/devpool-directory",
-     "state": "closed",
+     "state": "open",
      "title": "issue",
      "updated_at": "",
      "url": "",
      "user": null,
    },

repo: "test-repo",
});
await main();
const devpoolIssue = await getAllIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const devpoolIssue = await getAllIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME);
const devpoolIssues = await getAllIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME);

@Ekep-Obasi
Copy link
Author

I'm closing this PR, I think this issue had already been solved by @rndquu

@Ekep-Obasi Ekep-Obasi closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Close Assigned Issues
3 participants