-
Notifications
You must be signed in to change notification settings - Fork 139
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: labels from first invocation were being applied to future calls #251
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,25 @@ interface Repos { | |
// from the local copy. We are using the `PushEvent` to detect the change, | ||
// meaning the file running in cloud will be older than the one on master. | ||
let labelsCache: Labels; | ||
async function getLabels(github: GitHubAPI, repoPath: string) { | ||
async function getLabels(github: GitHubAPI, repoPath: string): Promise<Labels> { | ||
if (!labelsCache) { | ||
await refreshLabels(github, repoPath); | ||
} | ||
return labelsCache; | ||
const labels = { | ||
labels: labelsCache.labels.slice(0), | ||
} as Labels; | ||
const apiLabelsRes = await handler.getApiLabels(repoPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little worried here. Isn't this essentially completely bypassing the cache? Will this end up calling out to GCS constantly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only called once per function invocation, which only occurs rarely, e.g., when a new repo is created, or a label is deleted. I think we're going to need to get rid of the |
||
apiLabelsRes.apis.forEach(api => { | ||
labels.labels.push({ | ||
name: api.github_label, | ||
description: `Issues related to the ${api.display_name} API.`, | ||
color: createHash('md5') | ||
.update(api.api_shortname) | ||
.digest('hex') | ||
.slice(0, 6), | ||
}); | ||
}); | ||
return labels; | ||
} | ||
|
||
async function refreshLabels(github: GitHubAPI, repoPath: string) { | ||
|
@@ -60,18 +74,6 @@ async function refreshLabels(github: GitHubAPI, repoPath: string) { | |
labelsCache = JSON.parse( | ||
Buffer.from(data.content as string, 'base64').toString('utf8') | ||
); | ||
|
||
const apiLabelsRes = await handler.getApiLabels(repoPath); | ||
apiLabelsRes.apis.forEach(api => { | ||
labelsCache.labels.push({ | ||
name: api.github_label, | ||
description: `Issues related to the ${api.display_name} API.`, | ||
color: createHash('md5') | ||
.update(api.api_shortname) | ||
.digest('hex') | ||
.slice(0, 6), | ||
}); | ||
}); | ||
} | ||
|
||
function handler(app: Application) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of a
labels.slice(0)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this creates a copy of the
labels
so that we don't end up populating additional labels in the cache each time we access labels.creating a cache means that the labels are cached between invocations of cloud functions.