From 62a24e63a2926b2599f0633171bfdbbb8fbd189e Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 24 Aug 2021 23:23:59 +0300 Subject: [PATCH] Track PRs with no team as well --- compose-db.js | 48 +++++++++++++++++++++++++++++----------- src/paths/index/entry.js | 15 +++++++------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/compose-db.js b/compose-db.js index 02497b6..84e3a68 100644 --- a/compose-db.js +++ b/compose-db.js @@ -104,21 +104,43 @@ function processPulls(pullsRaw) { }); // Add teams, if available. - item.requested_teams.forEach((teamItem) => { + if (item.requested_teams.length > 0) { + item.requested_teams.forEach((teamItem) => { + const team = { + "id": teamItem.id, + "name": teamItem.name, + "avatar": `https://avatars.githubusercontent.com/t/${teamItem.id}?s=40&v=4`, + "slug": teamItem.slug, + "full_name": teamItem.name, + "full_slug": teamItem.slug, + "pull_count": 0, + }; + // Include parent data into full name and slug. + if (teamItem.parent) { + team.full_name = `${teamItem.parent.name}/${team.name}`; + team.full_slug = `${teamItem.parent.slug}/${team.slug}`; + } + + // Store the team if it hasn't been stored before. + if (typeof teams[team.id] == "undefined") { + teams[team.id] = team; + } + teams[team.id].pull_count++; + + // Reference the team. + pr.teams.push(team.id); + }); + } else { + // If there are no teams, use a fake "empty" team to track those PRs as well. const team = { - "id": teamItem.id, - "name": teamItem.name, - "avatar": `https://avatars.githubusercontent.com/t/${teamItem.id}?s=40&v=4`, - "slug": teamItem.slug, - "full_name": teamItem.name, - "full_slug": teamItem.slug, + "id": -1, + "name": "No team assigned", + "avatar": "", + "slug": "_", + "full_name": "No team assigned", + "full_slug": "_", "pull_count": 0, }; - // Include parent data into full name and slug. - if (teamItem.parent) { - team.full_name = `${teamItem.parent.name}/${team.name}`; - team.full_slug = `${teamItem.parent.slug}/${team.slug}`; - } // Store the team if it hasn't been stored before. if (typeof teams[team.id] == "undefined") { @@ -128,7 +150,7 @@ function processPulls(pullsRaw) { // Reference the team. pr.teams.push(team.id); - }); + } pulls.push(pr); }); diff --git a/src/paths/index/entry.js b/src/paths/index/entry.js index b12016f..d76dfcd 100644 --- a/src/paths/index/entry.js +++ b/src/paths/index/entry.js @@ -66,6 +66,9 @@ export default class EntryComponent extends LitElement { this._orderedTeams = Object.values(this._teams); this._orderedTeams.sort((a, b) => { + if (a.id === -1) return -1; + if (b.id === -1) return -1; + if (a.name > b.name) return 1; if (a.name < b.name) return -1; return 0; @@ -119,13 +122,11 @@ export default class EntryComponent extends LitElement { render(){ let pulls = []; - if (this._selectedTeam >= 0) { - this._pulls.forEach((pull) => { - if (pull.teams.includes(this._selectedTeam)) { - pulls.push(pull); - } - }); - } + this._pulls.forEach((pull) => { + if (pull.teams.includes(this._selectedTeam)) { + pulls.push(pull); + } + }); return html`