-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathupdate-submodule.py
More file actions
43 lines (36 loc) · 1.39 KB
/
update-submodule.py
File metadata and controls
43 lines (36 loc) · 1.39 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from e3.auth.gitlab import gen_gitlab_token
import gitlab
import os
# This script assumes that another project (hardcoded here as
# "eng/spark/spark2014") has a submodule pointing to our project. The purpose
# of this script is to create a merge request in that other project, that
# updates the submodule information to the current commit SHA.
base_url = os.environ["CI_SERVER_URL"]
project_name = "eng/spark/spark2014"
target_commit = os.environ["CI_COMMIT_SHORT_SHA"]
target_commit_long = os.environ["CI_COMMIT_SHA"]
target_branch = os.environ["CI_COMMIT_REF_NAME"]
commit_message = "Automatic submodule commit"
mr_title = "Automatic submodule commit"
mr_body = "no-issue-check"
def main():
gl = gitlab.Gitlab(base_url, private_token=gen_gitlab_token()["token"])
project = gl.projects.get(project_name)
mr_branch = f"automated-submodule-update-{target_commit}"
project.branches.create({"branch": mr_branch, "ref": target_branch})
project.update_submodule(
"why3", mr_branch, target_commit_long, commit_message=commit_message
)
mr = project.mergerequests.create(
{
"source_branch": mr_branch,
"target_branch": target_branch,
"title": mr_title,
"description": mr_body,
"labels": ["skip-ci"]
}
)
print(f"Merge request created: {mr.web_url}")
mr.approve()
if __name__ == "__main__":
main()