-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathclient.py
More file actions
28 lines (21 loc) · 845 Bytes
/
client.py
File metadata and controls
28 lines (21 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding:utf-8
import time
import requests
from commons.settings import GITLAB_TOKEN
from gitlab import GitLabApi
from util import parse_giturl
SUPPORT_GIT_TYPE = {'gitlab': GitLabApi(GITLAB_TOKEN)}
TIMEFORMAT_ISO8601 = '%Y-%m-%dT%H:%M:%S%z'
def fetch_project_commits(giturl, from_timestamp, until_timestamp=None):
scheme, host, namespace, project = parse_giturl(giturl)
if scheme is None:
return
git_type = host.split('.')[0]
git_api = SUPPORT_GIT_TYPE.get(git_type, None)
if git_api is None:
return
since = time.strftime(TIMEFORMAT_ISO8601, time.gmtime(from_timestamp + 1))
until = None
if until_timestamp is not None:
until = time.strftime(TIMEFORMAT_ISO8601, time.gmtime(until_timestamp))
return git_api.fetch_project_commits(scheme, host, namespace, project, since, until)