Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab-ci
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SECO Northern Europe
Yocto
infrastructure
gitlab-ci
Commits
1982a24d
Commit
1982a24d
authored
4 years ago
by
Tim Jaacks
Browse files
Options
Downloads
Patches
Plain Diff
Add script to check if integration branch is up to date
parent
a24b1a39
No related branches found
No related tags found
1 merge request
!26
Add script to check if integration branch is up to date
Pipeline
#8129
passed with stage
in 18 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_if_integration_branch_is_up_to_date.py
+122
-0
122 additions, 0 deletions
check_if_integration_branch_is_up_to_date.py
with
122 additions
and
0 deletions
check_if_integration_branch_is_up_to_date.py
0 → 100755
+
122
−
0
View file @
1982a24d
#!/usr/bin/env python3
import
common
import
argparse
import
sys
import
tempfile
from
furl
import
furl
from
git
import
GitCommandError
,
Repo
from
gitlab
import
Gitlab
,
GitlabGetError
def
check_if_integration_branch_is_up_to_date
(
manifest_project
,
integration_base
,
project
,
merge_request
,
):
gitlab
=
manifest_project
.
manager
.
gitlab
integration_branch
=
common
.
integration_branch_name
(
project
.
name
,
merge_request
.
source_branch
)
with
tempfile
.
TemporaryDirectory
()
as
manifest_dir
:
# Construct clone url containing access token
clone_url
=
furl
(
manifest_project
.
http_url_to_repo
)
clone_url
.
username
=
"
gitlab-ci
"
clone_url
.
password
=
gitlab
.
private_token
# Checkout manifest
try
:
manifest_repo
=
Repo
.
clone_from
(
clone_url
.
url
,
manifest_dir
,
branch
=
integration_branch
)
except
GitCommandError
as
e
:
sys
.
exit
(
"
ERROR: could not clone manifest repository
\n
"
+
str
(
e
))
# Get branches
try
:
integration_branch
=
manifest_repo
.
heads
[
integration_branch
]
except
IndexError
as
e
:
sys
.
exit
(
"
ERROR: branch
'
%s
'
not found
"
%
integration_branch
)
try
:
integration_base
=
manifest_repo
.
remote
().
refs
[
integration_base
]
except
IndexError
as
e
:
sys
.
exit
(
"
ERROR: branch
'
%s
'
not found
"
%
integration_base
)
# The integration branch is up to date if its parent is the integration base
up_to_date
=
integration_branch
.
commit
.
parents
[
0
]
==
integration_base
.
commit
return
up_to_date
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
--gitlab-url
"
,
help
=
"""
URL to the GitLab instance
"""
,
dest
=
"
gitlab_url
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--token
"
,
help
=
"""
GitLab REST API private access token
"""
,
dest
=
"
token
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--manifest-project
"
,
help
=
"""
name of the manifest project
"""
,
dest
=
"
manifest_project
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--integration-base
"
,
help
=
"""
manifest branch to branch off from
"""
,
dest
=
"
integration_base
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--project
"
,
help
=
"""
name of the project, as specified in the manifest
"""
,
dest
=
"
project
"
,
required
=
True
,
)
parser
.
add_argument
(
"
--merge-request
"
,
help
=
"""
project merge request IID containing the changes to be integrated
"""
,
dest
=
"
merge_request
"
,
required
=
True
,
)
args
,
_
=
parser
.
parse_known_args
()
gitlab
=
Gitlab
(
args
.
gitlab_url
,
private_token
=
args
.
token
)
manifest_project
=
common
.
get_project
(
gitlab
,
args
.
manifest_project
)
project
=
common
.
get_project
(
gitlab
,
args
.
project
)
try
:
merge_request
=
project
.
mergerequests
.
get
(
args
.
merge_request
,
retry_transient_errors
=
True
)
except
GitlabGetError
as
e
:
sys
.
exit
(
"
ERROR: could not get %s!%s: %s
"
%
(
project
.
name
,
args
.
merge_request
,
e
.
error_message
)
)
if
check_if_integration_branch_is_up_to_date
(
manifest_project
=
manifest_project
,
integration_base
=
args
.
integration_base
,
project
=
project
,
merge_request
=
merge_request
,
):
print
(
"
Integration branch is up to date.
"
)
else
:
sys
.
exit
(
"
Integration branch is not up to date. Please re-run the pipeline.
"
)
if
__name__
==
"
__main__
"
:
main
()
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