Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Alt
cb-util
Commits
d58ac99b
Commit
d58ac99b
authored
1 year ago
by
Christoph Alt
Browse files
Options
Downloads
Patches
Plain Diff
fixed the commit info querying
parent
abf6dcd7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#56999
passed
1 year ago
Stage: test
Stage: deploy
Stage: trigger
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cbutil/gitlab_api.py
+11
-6
11 additions, 6 deletions
cbutil/gitlab_api.py
with
11 additions
and
6 deletions
cbutil/gitlab_api.py
+
11
−
6
View file @
d58ac99b
...
@@ -30,15 +30,20 @@ def get_api_url_commits(base_api_url: str) -> str:
...
@@ -30,15 +30,20 @@ def get_api_url_commits(base_api_url: str) -> str:
return
f
"
{
base_api_url
}
/repository/commits
"
return
f
"
{
base_api_url
}
/repository/commits
"
def
get_last_commit
(
instance_url
:
str
,
project_id
:
Project_id
,
branch
:
str
=
''
):
def
get_last_commit
(
instance_url
:
str
,
project_id
:
Project_id
,
branch
:
str
=
''
,
commit
=
''
):
url
=
get_api_url_commits
(
get_api_url
(
instance_url
,
project_id
))
url
=
get_api_url_commits
(
get_api_url
(
instance_url
,
project_id
))
if
commit
:
url
=
f
"
{
url
}
/
{
commit
}
"
url
=
add_pagination
(
url
,
page
=
1
,
per_page
=
1
)
url
=
add_pagination
(
url
,
page
=
1
,
per_page
=
1
)
params
=
{
'
ref_name
'
:
branch
if
branch
else
'
master
'
}
params
=
{
'
ref_name
'
:
branch
if
branch
else
'
master
'
}
commit
=
requests
.
get
(
url
,
params
=
params
)
commit
=
requests
.
get
(
url
,
params
=
params
)
logger
.
info
(
f
"
requesting
{
url
}
with params
"
)
logger
.
info
(
f
"
requesting
{
url
}
with params
"
)
if
commit
.
status_code
!=
200
:
if
commit
.
status_code
!=
200
:
commit
.
raise_for_status
()
commit
.
raise_for_status
()
return
commit
.
json
()[
0
]
try
:
return
commit
.
json
()[
0
]
except
KeyError
:
return
commit
.
json
()
def
get_commit_infos_from_api
(
commit
:
dict
)
->
dict
:
def
get_commit_infos_from_api
(
commit
:
dict
)
->
dict
:
...
@@ -51,12 +56,12 @@ def get_git_infos_from_api(instance_url, project_id: Project_id,
...
@@ -51,12 +56,12 @@ def get_git_infos_from_api(instance_url, project_id: Project_id,
commit_key
=
"
commit
"
,
commit_key
=
"
commit
"
,
commit_msg_key
=
"
commit_message
"
,
commit_msg_key
=
"
commit_message
"
,
commit_env_key
=
None
):
commit_env_key
=
None
):
last_
commit
=
""
commit
=
""
if
commit_env_key
:
if
commit_env_key
:
last_commit
=
os
.
getenv
(
commit_env_key
,
None
)
commit
=
os
.
getenv
(
commit_env_key
,
None
)
last_commit
=
get_last_commit
(
instance_url
,
project_id
,
branch
=
branch
,
commit
=
commit
)
if
not
last_commit
:
last_commit
=
get_last_commit
(
instance_url
,
project_id
,
branch
=
branch
)
commit
,
commit_msg
=
get_commit_infos_from_api
(
last_commit
)
commit
,
commit_msg
=
get_commit_infos_from_api
(
last_commit
)
commit_msg
=
remove_newline
(
commit_msg
)
commit_msg
=
remove_newline
(
commit_msg
)
return
{
commit_key
:
commit
,
commit_msg_key
:
commit_msg
}
return
{
commit_key
:
commit
,
commit_msg_key
:
commit_msg
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment