| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c545504 commit 00f7e2e
1 file changed
| Original file line number | Diff line number | Diff 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() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments