|
| 1 | +from e3.auth.gitlab import gen_gitlab_token |
| 2 | +import gitlab |
| 3 | +import os |
| 4 | + |
| 5 | +# This script assumes that another project (hardcoded here as |
| 6 | +# "eng/spark/spark2014") has a submodule pointing to our project. The purpose |
| 7 | +# of this script is to create a merge request in that other project, that |
| 8 | +# updates the submodule information to the current commit SHA. |
| 9 | + |
| 10 | +base_url = os.environ["CI_SERVER_URL"] |
| 11 | +project_name = "eng/spark/spark2014" |
| 12 | +target_commit = os.environ["CI_COMMIT_SHORT_SHA"] |
| 13 | +target_commit_long = os.environ["CI_COMMIT_SHA"] |
| 14 | +target_branch = os.environ["CI_COMMIT_REF_NAME"] |
| 15 | +commit_message = "Automatic submodule commit" |
| 16 | +mr_title = "Automatic submodule commit" |
| 17 | +mr_body = "no-issue-check" |
| 18 | + |
| 19 | + |
| 20 | +def main(): |
| 21 | + |
| 22 | + gl = gitlab.Gitlab(base_url, private_token=gen_gitlab_token()["token"]) |
| 23 | + project = gl.projects.get(project_name) |
| 24 | + mr_branch = f"automated-submodule-update-{target_commit}" |
| 25 | + project.branches.create({"branch": mr_branch, "ref": target_branch.name}) |
| 26 | + project.update_submodule( |
| 27 | + "why3", mr_branch, target_commit_long, commit_message=commit_message |
| 28 | + ) |
| 29 | + mr = project.mergerequests.create( |
| 30 | + { |
| 31 | + "source_branch": mr_branch, |
| 32 | + "target_branch": target_branch.name, |
| 33 | + "title": mr_title, |
| 34 | + "description": mr_body, |
| 35 | + } |
| 36 | + ) |
| 37 | + print(f"Merge request created: {mr.web_url}") |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + main() |
0 commit comments