Beispiel #1
0
    def handle_merge_request(self):
        active_users = self.gl_helper.get_active_users()
        assignee = None
        if self.args.assignee:
            assignee = get_assignee(active_users, self.args.assignee)
            ui.info_2("Assigning to", assignee["name"])

        merge_request = self.ensure_merge_request()

        title = self.handle_title(merge_request)

        params = {
            "title": title,
            "target_branch": self.target_branch,
            "remove_source_branch": True,
        }
        if assignee:
            params["assignee_id"] = assignee["id"]

        self.gl_helper.update_merge_request(merge_request, **params)

        if self.args.accept:
            self.gl_helper.accept_merge_request(merge_request)

        ui.info(ui.green, "::",
                ui.reset, "See merge request at", merge_request["web_url"])
Beispiel #2
0
 def set_remotes(self):
     ui.info_1("Setting remote URLs")
     manifest = self.load_manifest()
     for repo in manifest.repos:
         full_path = self.joinpath(repo.src)
         _, old_url = tsrc.git.run_git(full_path, "remote", "get-url", "origin", raises=False)
         if old_url != repo.url:
             ui.info_2(repo.src, old_url, "->", repo.url)
             tsrc.git.run_git(full_path, "remote", "set-url", "origin", repo.url)
Beispiel #3
0
 def update_manifest(self):
     ui.info_2("Updating manifest")
     if not self.manifest_clone_path.exists():
         message = "Could not find manifest in {}. "
         message += "Did you run `tsrc init` ?"
         raise tsrc.Error(message.format(self.manifest_clone_path))
     cmd = ("fetch", "--prune", "origin")
     tsrc.git.run_git(self.manifest_clone_path, *cmd)
     cmd = ("reset", "--hard", "@{u}")
     tsrc.git.run_git(self.manifest_clone_path, *cmd)
     return self.load_manifest()
Beispiel #4
0
 def copy_files(self, manifest):
     for src, dest in manifest.copyfiles:
         src_path = self.joinpath(src)
         dest_path = self.joinpath(dest)
         ui.info_2("Copying", src, "->", dest)
         if dest_path.exists():
             # Re-set the write permissions on the file:
             dest_path.chmod(stat.S_IWRITE)
         src_path.copy(dest_path)
         # Make sure perms are read only for everyone
         dest_path.chmod(0o10444)
Beispiel #5
0
 def accept_merge_request(self, merge_request):
     project_id = merge_request["project_id"]
     merge_request_iid = merge_request["iid"]
     ui.info_2("Merging when build succeeds", ui.ellipsis, end="")
     url = "/projects/%s/merge_requests/%s/merge" % (project_id,
                                                     merge_request_iid)
     data = {
         "merge_when_pipeline_succeeds": True,
     }
     self.make_request("PUT", url, data=data)
     ui.info("done", ui.check)
Beispiel #6
0
 def ensure_merge_request(self):
     merge_request = self.gl_helper.find_opened_merge_request(self.project_id,
                                                              self.source_branch)
     if merge_request:
         ui.info_2("Found existing merge request: !%s" % merge_request["iid"])
         return merge_request
     else:
         res = self.gl_helper.create_merge_request(self.project_id, self.source_branch,
                                                   title=self.source_branch,
                                                   target_branch=self.target_branch)
         return res
Beispiel #7
0
def main(args):
    workspace = tsrc.cli.get_workspace(args)
    errors = list()
    for _, repo, full_path in workspace.enumerate_repos():
        ui.info_2("Running", "`%s`" % args.cmd_as_str, "on", ui.bold, repo.src)
        returncode = subprocess.call(args.cmd, cwd=full_path, shell=args.shell)
        if returncode != 0:
            errors.append(repo.src)
    if errors:
        ui.info(ui.cross, ui.red, "foreach failed")
        for error in errors:
            ui.info("*", ui.bold, error)
        sys.exit(1)
    else:
        ui.info(ui.check, "All done")
Beispiel #8
0
 def create_merge_request(self,
                          project_id,
                          source_branch,
                          *,
                          title,
                          target_branch="master"):
     ui.info_2("Creating merge request", ui.ellipsis, end="")
     url = "/projects/%i/merge_requests" % project_id
     data = {
         "source_branch": source_branch,
         "target_branch": target_branch,
         "title": title,
         "project_id": project_id,
     }
     result = self.make_request("POST", url, data=data)
     ui.info("done", ui.check)
     return result
Beispiel #9
0
 def push(self):
     ui.info_2("Running git push")
     cmd = ["push", "-u", "origin", "%s:%s" % (self.source_branch, self.source_branch)]
     if self.args.force:
         cmd.append("--force")
     tsrc.git.run_git(self.repo_path, *cmd)