mirror of https://github.com/zulip/zulip.git
team: Map repo name to tab name in frontend.
fetch-contributor-data's job is to fetch the data. How the data is presented in frontend is something it don't have to know about.
This commit is contained in:
parent
053af4c19d
commit
2967294398
|
@ -1,26 +1,25 @@
|
||||||
const contributors_list = page_params.contrib;
|
const contributors_list = page_params.contrib;
|
||||||
|
|
||||||
// `repos` are repositories to be shown as tabs, whereas `hidden_repos` are
|
const repo_name_to_tab_name = {
|
||||||
// repositories that should count towards the total but not have tabs.
|
zulip: "server",
|
||||||
const repos = [
|
"zulip-desktop": "desktop",
|
||||||
"server",
|
"zulip-mobile": "mobile",
|
||||||
"desktop",
|
"python-zulip-api": "python-zulip-api",
|
||||||
"mobile",
|
"zulip-js": "zulip-js",
|
||||||
"python-zulip-api",
|
zulipbot: "zulipbot",
|
||||||
"zulip-js",
|
"zulip-terminal": "terminal",
|
||||||
"zulipbot",
|
"zulip-ios-legacy": "",
|
||||||
"terminal",
|
"zulip-android": "",
|
||||||
];
|
};
|
||||||
const hidden_repos = ["zulip-android", "zulip-ios-legacy"];
|
|
||||||
|
|
||||||
// Remember the loaded repositories so that HTML is not redundantly edited
|
// Remember the loaded repositories so that HTML is not redundantly edited
|
||||||
// if a user leaves and then revisits the same tab.
|
// if a user leaves and then revisits the same tab.
|
||||||
const loaded_repos = [];
|
const loaded_repos = [];
|
||||||
|
|
||||||
function contrib_total_commits(contrib) {
|
function contrib_total_commits(contributor) {
|
||||||
let commits = 0;
|
let commits = 0;
|
||||||
repos.concat(hidden_repos).forEach((repo) => {
|
Object.keys(repo_name_to_tab_name).forEach((repo_name) => {
|
||||||
commits += contrib[repo] || 0;
|
commits += contributor[repo_name] || 0;
|
||||||
});
|
});
|
||||||
return commits;
|
return commits;
|
||||||
}
|
}
|
||||||
|
@ -35,9 +34,9 @@ export default function render_tabs() {
|
||||||
// contributors who have atleast the same number of contributions than the last contributor
|
// contributors who have atleast the same number of contributions than the last contributor
|
||||||
// returned by the API for zulip/zulip repo.
|
// returned by the API for zulip/zulip repo.
|
||||||
const least_server_commits = _.chain(contributors_list)
|
const least_server_commits = _.chain(contributors_list)
|
||||||
.filter("server")
|
.filter("zulip")
|
||||||
.sortBy("server")
|
.sortBy("zulip")
|
||||||
.value()[0].server;
|
.value()[0].zulip;
|
||||||
|
|
||||||
const total_tab_html = _.chain(contributors_list)
|
const total_tab_html = _.chain(contributors_list)
|
||||||
.map((c) => ({
|
.map((c) => ({
|
||||||
|
@ -54,29 +53,33 @@ export default function render_tabs() {
|
||||||
|
|
||||||
$("#tab-total").html(total_tab_html);
|
$("#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.
|
// 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", () => {
|
$("#" + tab_name).on("click", () => {
|
||||||
if (!loaded_repos.includes(repo)) {
|
if (!loaded_repos.includes(repo_name)) {
|
||||||
const html = _.chain(contributors_list)
|
const html = _.chain(contributors_list)
|
||||||
.filter(repo)
|
.filter(repo_name)
|
||||||
.sortBy(repo)
|
.sortBy(repo_name)
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((c) =>
|
.map((c) =>
|
||||||
template({
|
template({
|
||||||
name: c.name,
|
name: c.name,
|
||||||
avatar: c.avatar,
|
avatar: c.avatar,
|
||||||
commits: c[repo],
|
commits: c[repo_name],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.value()
|
.value()
|
||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
$("#tab-" + repo).html(html);
|
$("#tab-" + tab_name).html(html);
|
||||||
|
|
||||||
loaded_repos.push(repo);
|
loaded_repos.push(repo_name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,15 @@ class Contributor(TypedDict):
|
||||||
|
|
||||||
logger = logging.getLogger('zulip.fetch_contributors_json')
|
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] = []
|
contributors: List[Contributor] = []
|
||||||
retry_attempts = 0
|
retry_attempts = 0
|
||||||
page_index = 1
|
page_index = 1
|
||||||
|
|
||||||
|
api_link = f"https://api.github.com/repos/zulip/{repo_name}/contributors"
|
||||||
|
|
||||||
while True:
|
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:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
|
@ -77,41 +79,26 @@ def write_to_disk(json_data: ContributorsJSON, out_file: str) -> None:
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
|
||||||
def update_contributor_data_file() -> None:
|
def update_contributor_data_file() -> None:
|
||||||
"""
|
# This list should hold all repositories that should be included in
|
||||||
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
|
|
||||||
# the total count, including those that should *not* have tabs on the team
|
# the total count, including those that should *not* have tabs on the team
|
||||||
# page (e.g. if they are deprecated).
|
# page (e.g. if they are deprecated).
|
||||||
repositories = {
|
repo_names = ['zulip', 'zulip-desktop', 'zulip-mobile', 'python-zulip-api', 'zulip-js', 'zulipbot',
|
||||||
'server': 'https://api.github.com/repos/zulip/zulip/contributors',
|
'zulip-terminal', 'zulip-ios-legacy', 'zulip-android']
|
||||||
'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',
|
|
||||||
}
|
|
||||||
|
|
||||||
data: ContributorsJSON = dict(date=str(date.today()), contrib=[])
|
data: ContributorsJSON = dict(date=str(date.today()), contrib=[])
|
||||||
contribs_list: Dict[str, Dict[str, Union[str, int]]] = {}
|
contribs_list: Dict[str, Dict[str, Union[str, int]]] = {}
|
||||||
|
|
||||||
for name, link in repositories.items():
|
for repo_name in repo_names:
|
||||||
contributors = fetch_contributors(link, args.max_retries)
|
contributors = fetch_contributors(repo_name, args.max_retries)
|
||||||
for contributor in contributors:
|
for contributor in contributors:
|
||||||
username = contributor['login']
|
username = contributor['login']
|
||||||
if username in contribs_list:
|
if username in contribs_list:
|
||||||
contribs_list[username][name] = contributor['contributions']
|
contribs_list[username][repo_name] = contributor['contributions']
|
||||||
else:
|
else:
|
||||||
contribs_list[username] = {
|
contribs_list[username] = {
|
||||||
'avatar': contributor['avatar_url'],
|
'avatar': contributor['avatar_url'],
|
||||||
'name': username,
|
'name': username,
|
||||||
name: contributor['contributions']
|
repo_name: contributor['contributions']
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove duplicate contributions count
|
# remove duplicate contributions count
|
||||||
|
|
Loading…
Reference in New Issue