From f8554a18c3e84793b8bfd1c0f5d1a3a90c42be5d Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 28 Jan 2020 17:12:58 -0800 Subject: [PATCH 1/2] fix: labels from first invocation were being applied to future calls --- packages/label-sync/src/label-sync.ts | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/label-sync/src/label-sync.ts b/packages/label-sync/src/label-sync.ts index 8dc4415a948..02282bb7dd7 100644 --- a/packages/label-sync/src/label-sync.ts +++ b/packages/label-sync/src/label-sync.ts @@ -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 { if (!labelsCache) { await refreshLabels(github, repoPath); } - return labelsCache; + const labels = { + labels: labelsCache.labels.slice(0) + } as Labels; + const apiLabelsRes = await handler.getApiLabels(repoPath); + 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) { @@ -133,7 +135,7 @@ handler.getApiLabels = async ( const repo = (JSON.parse( publicRepos[0].toString() ) as PublicReposResponse).repos.find(repo => { - return repo.repo === repoPath && repo.github_label !== ''; + return repo.repo === repoPath && repo.github_label !== ""; }); if (repo) { From eb8a8756a69b52c4a2ee26632678ec6a5bad614e Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 28 Jan 2020 17:23:37 -0800 Subject: [PATCH 2/2] chore: fix linting --- packages/label-sync/src/label-sync.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/label-sync/src/label-sync.ts b/packages/label-sync/src/label-sync.ts index 02282bb7dd7..55839082f4e 100644 --- a/packages/label-sync/src/label-sync.ts +++ b/packages/label-sync/src/label-sync.ts @@ -47,7 +47,7 @@ async function getLabels(github: GitHubAPI, repoPath: string): Promise { await refreshLabels(github, repoPath); } const labels = { - labels: labelsCache.labels.slice(0) + labels: labelsCache.labels.slice(0), } as Labels; const apiLabelsRes = await handler.getApiLabels(repoPath); apiLabelsRes.apis.forEach(api => { @@ -135,7 +135,7 @@ handler.getApiLabels = async ( const repo = (JSON.parse( publicRepos[0].toString() ) as PublicReposResponse).repos.find(repo => { - return repo.repo === repoPath && repo.github_label !== ""; + return repo.repo === repoPath && repo.github_label !== ''; }); if (repo) {