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

Add Caching Functionality when Fetching Issue Labels for Deployment Reviews #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alecbuchanan
Copy link

@alecbuchanan alecbuchanan commented Jan 14, 2025

Addresses https://github.com/github/fs-tech-tooling/issues/85

Enhancements to GitHubDeploymentManager:

  • Added methods fetchLabelsForIssue and fetchLabelsForRepo to fetch labels for a specific issue and all issues in a repository, respectively. [1] [2]
  • Introduced a label cache with methods getIssueLabels and initializeLabelCache to improve performance by caching labels. [1] [2]

Updates to constants and types:

  • Added ISSUE_STATES constant to represent different issue states (open, closed, all).
  • Introduced GitHubLabel interface to define the structure of a GitHub label.

Testing improvements:

  • Added comprehensive tests for GitHubDeploymentManager to cover label fetching and caching functionalities.
  • Created LabelMockFactory to generate mock labels and responses for testing purposes.

- Add in-memory cache for issue labels
- Add cache initialization methods
- Add cache hit/miss logging
- Add cache state management
- Support optional cache bypass
@alecbuchanan
Copy link
Author

All tests passing:
Screenshot 2025-01-13 at 7 48 03 PM

Cache initialized with 77 open issues:
Screenshot 2025-01-13 at 7 54 40 PM

77 Open issues in Octodemo at the same time I ran locally:
Screenshot 2025-01-13 at 7 54 33 PM

4 Issues in Warn State >7 days old, which matches what I see in the UI:
Screenshot 2025-01-13 at 7 55 00 PM

@alecbuchanan
Copy link
Author

@davelosert Apologies for all this dist files, should I have separated these out in a different PR?

Copy link

@davelosert davelosert left a comment

Choose a reason for hiding this comment

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

Hey @alecbuchanan,

thank you again for this PR. I left a few minor comments, but all in all, gerat job!

The dist-folders are fine - they even need to be generated within the PR in order for a clean release. So please, after your changes, rebuild and recommit the dist file as well! :)

let manager: GitHubDeploymentManager;

beforeEach(() => {
vi.clearAllMocks();

Choose a reason for hiding this comment

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

Can we put this into a "afterEach" call for cleaness?

open: 'open',
closed: 'closed',
all: 'all',
} as const;

Choose a reason for hiding this comment

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

I would define this only as type and derive it directly from the GitHub API.
We only use it as non-type in the GitHubDeploymentManager, and for one spot I believe an ENUM-kind-of-definition is too much.

Given they GitHubDeploymentManager already has a dependency to octokit.js, lets derive the issue state from there and then just use a string as the default value (I will leave a comment on those code references as well.)

}

async fetchLabelsForRepo(
state: keyof typeof ISSUE_STATES = ISSUE_STATES.open,

Choose a reason for hiding this comment

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

As described in my comment for constants.ts, let's not use a pseudo-enum here but let's keep things simple:

Derive the issue-state type from the octokit types and then just use a string for the default definition here. it would look something like this:

  type OctokitType = InstanceType<typeof Octokit>;

	type Issue = Awaited<
		ReturnType<OctokitType["rest"]["issues"]["listForRepo"]>
	>["data"][0];
	type IssueState = Issue["state"];

  [...]
  async fetchLabelsForRepo(
    state: IssueState = 'open'
  [...]

}

private async initializeLabelCache(
state: keyof typeof ISSUE_STATES = ISSUE_STATES.open,

Choose a reason for hiding this comment

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

Same as above! :)

description?: string | null;
color?: string | null;
default?: boolean;
}

Choose a reason for hiding this comment

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

Derive it from Octokit here as you did in the LabelMockFactory.ts file

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.

2 participants