Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
team: Map repo name to tab name in frontend.
Vishnu KS2190dbd4b022
diff --git a/static/js/portico/team.js b/static/js/portico/team.jsindex be5044f7023..bec394581d5 100644--- a/static/js/portico/team.js+++ b/static/js/portico/team.js@@ -1,26 +1,25 @@const contributors_list = page_params.contrib;-// `repos` are repositories to be shown as tabs, whereas `hidden_repos` are-// repositories that should count towards the total but not have tabs.-const repos = [- "server",- "desktop",- "mobile",- "python-zulip-api",- "zulip-js",- "zulipbot",- "terminal",-];-const hidden_repos = ["zulip-android", "zulip-ios-legacy"];+const repo_name_to_tab_name = {+ zulip: "server",+ "zulip-desktop": "desktop",+ "zulip-mobile": "mobile",+ "python-zulip-api": "python-zulip-api",+ "zulip-js": "zulip-js",+ zulipbot: "zulipbot",+ "zulip-terminal": "terminal",+ "zulip-ios-legacy": "",+ "zulip-android": "",+};// Remember the loaded repositories so that HTML is not redundantly edited// if a user leaves and then revisits the same tab.const loaded_repos = [];-function contrib_total_commits(contrib) {+function contrib_total_commits(contributor) {let commits = 0;- repos.concat(hidden_repos).forEach((repo) => {- commits += contrib[repo] || 0;+ Object.keys(repo_name_to_tab_name).forEach((repo_name) => {+ commits += contributor[repo_name] || 0;});return commits;}@@ -35,9 +34,9 @@ export default function render_tabs() {// contributors who have atleast the same number of contributions than the last contributor// returned by the API for zulip/zulip repo.const least_server_commits = _.chain(contributors_list)- .filter("server")- .sortBy("server")- .value()[0].server;+ .filter("zulip")+ .sortBy("zulip")+ .value()[0].zulip;const total_tab_html = _.chain(contributors_list).map((c) => ({@@ -54,29 +53,33 @@ export default function render_tabs() {$("#tab-total").html(total_tab_html);- for (const repo of repos) {+ for (const repo_name of Object.keys(repo_name_to_tab_name)) {+ const tab_name = repo_name_to_tab_name[repo_name];+ if (!tab_name) {+ continue;+ }// Set as the loading template for now, and load when clicked.- $("#tab-" + repo).html($("#loading-template").html());+ $("#tab-" + tab_name).html($("#loading-template").html());- $("#" + repo).on("click", () => {- if (!loaded_repos.includes(repo)) {+ $("#" + tab_name).on("click", () => {+ if (!loaded_repos.includes(repo_name)) {const html = _.chain(contributors_list)- .filter(repo)- .sortBy(repo)+ .filter(repo_name)+ .sortBy(repo_name).reverse().map((c) =>template({name: c.name,avatar: c.avatar,- commits: c[repo],+ commits: c[repo_name],}),).value().join("");- $("#tab-" + repo).html(html);+ $("#tab-" + tab_name).html(html);- loaded_repos.push(repo);+ loaded_repos.push(repo_name);}});}diff --git a/tools/fetch-contributor-data b/tools/fetch-contributor-dataindex b4220b036f3..43e80a26b31 100755--- a/tools/fetch-contributor-data+++ b/tools/fetch-contributor-data@@ -48,13 +48,15 @@ class Contributor(TypedDict):logger = logging.getLogger('zulip.fetch_contributors_json')-def fetch_contributors(repo_link: str, max_retries: int) -> List[Contributor]:+def fetch_contributors(repo_name: str, max_retries: int) -> List[Contributor]:contributors: List[Contributor] = []retry_attempts = 0page_index = 1+ api_link = f"https://api.github.com/repos/zulip/{repo_name}/contributors"+while True:- response: requests.Response = requests.get(f"{repo_link}?page={page_index}", verify=os.environ.get('CUSTOM_CA_CERTIFICATES'))+ response: requests.Response = requests.get(f"{api_link}?page={page_index}", verify=os.environ.get('CUSTOM_CA_CERTIFICATES'))if response.status_code == 200:data = response.json()if len(data) == 0:@@ -77,41 +79,26 @@ def write_to_disk(json_data: ContributorsJSON, out_file: str) -> None:f.write("\n")def update_contributor_data_file() -> None:- """- Get contributors data from Github and insert them into a temporary- dictionary. Retry fetching each repository if responded with non HTTP 200- status.- """-- # This dictionary should hold all repositories that should be included in+ # This list should hold all repositories that should be included in# the total count, including those that should *not* have tabs on the team# page (e.g. if they are deprecated).- repositories = {- 'server': 'https://api.github.com/repos/zulip/zulip/contributors',- 'desktop': 'https://api.github.com/repos/zulip/zulip-desktop/contributors',- 'mobile': 'https://api.github.com/repos/zulip/zulip-mobile/contributors',- 'python-zulip-api': 'https://api.github.com/repos/zulip/python-zulip-api/contributors',- 'zulip-js': 'https://api.github.com/repos/zulip/zulip-js/contributors',- 'zulipbot': 'https://api.github.com/repos/zulip/zulipbot/contributors',- 'terminal': 'https://api.github.com/repos/zulip/zulip-terminal/contributors',- 'zulip-ios-legacy': 'https://api.github.com/repos/zulip/zulip-ios-legacy/contributors',- 'zulip-android': 'https://api.github.com/repos/zulip/zulip-android/contributors',- }+ repo_names = ['zulip', 'zulip-desktop', 'zulip-mobile', 'python-zulip-api', 'zulip-js', 'zulipbot',+ 'zulip-terminal', 'zulip-ios-legacy', 'zulip-android']data: ContributorsJSON = dict(date=str(date.today()), contrib=[])contribs_list: Dict[str, Dict[str, Union[str, int]]] = {}- for name, link in repositories.items():- contributors = fetch_contributors(link, args.max_retries)+ for repo_name in repo_names:+ contributors = fetch_contributors(repo_name, args.max_retries)for contributor in contributors:username = contributor['login']if username in contribs_list:- contribs_list[username][name] = contributor['contributions']+ contribs_list[username][repo_name] = contributor['contributions']else:contribs_list[username] = {'avatar': contributor['avatar_url'],'name': username,- name: contributor['contributions']+ repo_name: contributor['contributions']}# remove duplicate contributions count