Created
May 7, 2021 19:48
-
-
Save jbontech/39dd2bc704eabc8269aa6f5ed3afe5be to your computer and use it in GitHub Desktop.
Python Gitlab API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import gitlab | |
from prettytable import PrettyTable | |
############################# | |
# THIS SCRIPT WILL PRINT THE SHORT COMMIT_ID,AUTHOR,DATE,TITLE OF COMMIT FROM GITLAB API | |
############################## | |
########################################################################################### | |
# 1. Create the personal access token in the gitlab profile settings then user in th eprivate_token | |
# 2. And get the project id from your project | |
# 3. Change the Branch name and Date time state to need the Data from the specific time internal | |
# Note: | |
# Please install depedency for this script | |
# pip3 install -r requirments.txt | |
############################################################################################ | |
############################################################################################ | |
# +-----------+-------------------+-------------------------------+-------------------------------------+ | |
# | Commit_id | Auther_name | Date | Titile | | |
# +-----------+-------------------+-------------------------------+-------------------------------------+ | |
# | 3807f99f | jothibasu.kamaraj | 2021-05-07T17:42:24.000+05:30 | Adding new change to gitlab-ci file | | |
# | 0d31761b | jothibasu.kamaraj | 2021-05-07T02:02:25.000+05:30 | Adding the Frontend build also | | |
# | 36d46156 | jothibasu.kamaraj | 2021-05-07T01:24:56.000+05:30 | change the runnger to aws | | |
# | 3807f99f | jothibasu.kamaraj | 2021-05-07T17:42:24.000+05:30 | Adding new change to gitlab-ci file | | |
# | 0d31761b | jothibasu.kamaraj | 2021-05-07T02:02:25.000+05:30 | Adding the Frontend build also | | |
# | 36d46156 | jothibasu.kamaraj | 2021-05-07T01:24:56.000+05:30 | change the runnger to aws | | |
# | 3807f99f | jothibasu.kamaraj | 2021-05-07T17:42:24.000+05:30 | Adding new change to file | | |
# | 0d31761b | jothibasu.kamaraj | 2021-05-07T02:02:25.000+05:30 | Adding the Frontend build also | | |
# | 36d46156 | jothibasu.kamaraj | 2021-05-07T01:24:56.000+05:30 | change the runnger to aws | | |
# +-----------+-------------------+-------------------------------+-------------------------------------+ | |
######################################################################################### | |
gl = gitlab.Gitlab('https://gitlab.com', private_token='***********') | |
commits_obj = gl.projects.get(XXXXXXXXX).commits.list(ref_name='<branch-name>',since='2021-05-06T00:00:00Z') | |
commits = [t.attributes for t in commits_obj] | |
t = PrettyTable(['Commit_id', 'Auther_name', 'Date', 'Titile']) | |
for d1 in commits: | |
for attribue in commits: | |
t.add_row([str(attribue['short_id']), str(attribue['author_name']), str(attribue['committed_date']), str(attribue['title'])]) | |
print(t) | |
with open('commits.txt', 'w') as outfile: | |
outfile.write(str(t)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prettytable==2.1.0 | |
python-gitlab==2.7.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment