Skip to content

Instantly share code, notes, and snippets.

@wuriyanto48
Created November 30, 2023 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wuriyanto48/b07341bf8a7bce1d2f56191c64f3f387 to your computer and use it in GitHub Desktop.
Save wuriyanto48/b07341bf8a7bce1d2f56191c64f3f387 to your computer and use it in GitHub Desktop.
(Python) Gitlab REST API get commit by user
import requests
import ujson as json
header ={
'PRIVATE-TOKEN': 'your_token'
}
def get_commits_by_user(project_id, email, since, until, branch):
json_loads_of_commit = []
params = {
"since": since,
"until": until,
"ref_name": branch
}
url_p = "https://gitlab.mydomain.com/api/v4/projects/%s/repository/commits" % project_id
r = requests.get(url_p, params=params, headers=header)
print(r.url)
c = 0
while r.status_code == 200:
jsLoad = json.loads(r.content)
newDate = jsLoad[-1]["committed_date"]
if (params["until"] == newDate):
break
user_commits = []
for cm in jsLoad:
if cm["author_email"] == email:
user_commits.append(cm)
c += 1
json_loads_of_commit.append(user_commits)
params["until"] = newDate
params["per_page"] = 100
r = requests.get(url_p, params, headers=header)
print(len(json_loads_of_commit))
print(json.dumps(json_loads_of_commit))
if __name__ == '__main__':
since = "2023-11-01T00:00:42.000+01:00"
until = "2023-12-30T00:00:42.000+01:00"
get_commits_by_user('20000', 'who@gmail.com', since, until, "development")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment