Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 00f7e2e

Browse filesBrowse files
author
zhangsheng
committed
use this script to get specific branch(for instance, release branch) latest modified time and reversed sort, then dump the result to .md file.
1 parent c545504 commit 00f7e2e
Copy full SHA for 00f7e2e

File tree

Expand file treeCollapse file tree

1 file changed

+55
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+55
-0
lines changed
Open diff view settings
Collapse file

‎tools/python_branch_history.py‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import base64
2+
import time
3+
import os
4+
import gitlab
5+
6+
def main():
7+
# token authentication from config file
8+
gl = gitlab.Gitlab.from_config(config_files=['/Users/victorzhang/.python-gitlab.cfg'])
9+
10+
# projects
11+
# Note: difference among gl.projects.list() / gl.projects.list(all=True) / gl.projects.owned()
12+
projects = gl.projects.list(all=True)
13+
14+
project_release_branches = []
15+
16+
for project in projects:
17+
# use try/except to avoid script exit from exception when there's no 'release' branch
18+
try:
19+
project_release_branch = project.branches.get('release')
20+
except Exception:
21+
project_release_branch = None
22+
23+
if project_release_branch is not None :
24+
latest_comitted_date = project_release_branch.commit['committed_date']
25+
project_release_branches.append({'name':project.name, 'latest_modified':latest_comitted_date})
26+
27+
28+
# Sort branches by modified time
29+
project_release_branches.sort(key=lambda r: r['latest_modified'], reverse=True)
30+
31+
# print result
32+
export(project_release_branches)
33+
34+
def export(branches):
35+
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
36+
rel_path = "release_branches.md"
37+
abs_file_path = os.path.join(script_dir, rel_path)
38+
with open(abs_file_path, mode="w") as out_file:
39+
out_file.write("|Project name|release branch latest modified time|\n")
40+
out_file.write("|---|---|\n")
41+
for branch in branches:
42+
project_name = branch['name']
43+
latest_modified = branch['latest_modified']
44+
45+
print(' project name: ' + project_name + ' | ' + 'release branch latest modified time: ' + latest_modified)
46+
47+
out_file.write("|")
48+
out_file.write(project_name)
49+
out_file.write("|")
50+
out_file.write(latest_modified)
51+
out_file.write("|")
52+
out_file.write("|\n")
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.