Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Abstracted code logic #108

Merged
merged 11 commits into from
Mar 14, 2023
Merged

Abstracted code logic #108

merged 11 commits into from
Mar 14, 2023

Conversation

Bullrich
Copy link
Contributor

@Bullrich Bullrich commented Feb 20, 2023

Abstracted GitHub api interaction from the runner method.

This is the first step into isolating the code so it is easier to read.

Second step will isolate the logic

@Bullrich Bullrich self-assigned this Feb 20, 2023
@Bullrich Bullrich marked this pull request as ready for review March 6, 2023 11:46
@Bullrich Bullrich requested a review from a team as a code owner March 6, 2023 11:46
Copy link
Contributor

@rzadp rzadp left a comment

Choose a reason for hiding this comment

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

I like it 👍 Feels good to abstract that logic.

@@ -69,7 +70,8 @@ describe("Configuration", () => {

setup({ rules: [badRule] });

expect(await runChecks({ pr: basePR, octokit, logger, finishProcessReviews: null })).toBe("failure");
const api = new GitHubApi(basePR, { logger, finishProcessReviews: null, octokit });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const api = new GitHubApi(basePR, { logger, finishProcessReviews: null, octokit });
const api = new GitHubApi(basePR, { logger, octokit });

It's not taken by GitHubApi. Same in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid it's a requirement in the object union that the method is receiving:

Argument of type '{ pr: PR; octokit: Octokit & { paginate: PaginateInterface; } & RestEndpointMethods & Api; logger: TestLogger; }' is not assignable to parameter of type 'Context & { pr: PR; }'.
Property 'finishProcessReviews' is missing in type '{ pr: PR; octokit: Octokit & { paginate: PaginateInterface; } & RestEndpointMethods & Api; logger: TestLogger; }' but required in type 'Context'.ts(2345)

I'll look into cleaning it in the future

@mutantcornholio
Copy link
Contributor

I feel like this duplicates the purpose of opstooling-integrations. Should we consider reusing it instead?

@Bullrich
Copy link
Contributor Author

Bullrich commented Mar 6, 2023

opstooling-integrations

I would be up to use it but would need to check if I can adapt the specific endpoints and combinations that are being called.

Some stuff, like the following, may not be that straightforward to migrate.

octokit.paginate(
      this.octokit.rest.teams.listMembersInOrg,
      { org:pr.base.repo.owner.login, team_slug, per_page: maxGithubApiTeamMembersPerPage },
      (response) => response.data.map(({ login }) => login),
    );

And I would still keep it in a wrapper so it can be tested easier.

But this PR would be a step forward into that direction

@mutantcornholio
Copy link
Contributor

Some stuff, like the following, may not be that straightforward to migrate.

octokit.paginate(
      this.octokit.rest.teams.listMembersInOrg,
      { org:pr.base.repo.owner.login, team_slug, per_page: maxGithubApiTeamMembersPerPage },
      (response) => response.data.map(({ login }) => login),
    );

We have paginated methods there :)

And I would still keep it in a wrapper so it can be tested easier.

One of the major points of creating opstooling-integrations was this exact goal: providing mocks for the endpoints from ground up, ease of use with jest.mock.

But this PR would be a step forward into that direction

Cool

@Bullrich Bullrich merged commit e636d91 into master Mar 14, 2023
@Bullrich Bullrich deleted the bullrich/abstraction branch March 14, 2023 11:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants