def projectid(self, token=None) -> int: # The path should be, as an example taking alpine/aports from gitlab.alpinelinux.org # $XDG_CACHE_HOME/mkmr/gitlab.alpinelinux.org/alpine/aports/project-id cachedir = create_dir( find_cache() / self.host.replace("https://", "").replace("/", ".") / self.user / self.project) cachepath = cachedir / "project-id" if cachepath.is_file(): self.projectid = int(cachepath.read_text()) return self.projectid """ Call into the gitlab API to get the project id """ from urllib.request import Request, urlopen import json req = Request(self.endpoint) if token is not None: req.add_header("Private-Token", token) f = urlopen(req).read() j = json.loads(f.decode("utf-8")) cachepath.write_text(str(j["id"])) self.projectid = j["id"] return self.projectid
"Failed to create merge request see below for error message:\n{}".format( e.error_message ) ) sys.exit(1) print("id:", mr.attributes["iid"]) print("title:", mr.attributes["title"]) print("state:", mr.attributes["state"]) print("url:", mr.attributes["web_url"]) try: # This path should be, taking alpine/aports from gitlab.alpinelinux.org as example: # $XDG_CACHE_HOME/mkmr/gitlab.alpinelinux.org/alpine/aports/branches/$source_branch cachepath = create_file( find_cache() / upstream.host.replace("https://", "").replace("/", ".") / upstream.user / upstream.project / "branches" / source_branch ) cachepath.write_text(str(mr.attributes["iid"])) except ValueError: print( "Failed to write to cache, merging by passing the name of the branch won't be available" ) print("Error: {}".format(sys.exc_info()[0])) if __name__ == "__main__":
sys.exit(1) remote = API(repo, options.remote) try: config = Config(options, remote.host) except ValueError as e: print(e) sys.exit(1) gl = config.get_gitlab() name = mrnum if not mrnum.isdigit(): try: cachepath = find_cache() # This path should be, taking alpine/aports from gitlab.alpinelinux.org as example: # $XDG_CACHE_HOME/mkmr/gitlab.alpinelinux.org/alpine/aports/branches/$source_branch cachepath = ( cachepath / remote.host.replace("https://", "").replace("/", ".") / remote.user / remote.project / "branches" / name) mrnum = cachepath.read_text() except FileNotFoundError: print("branch name given, {}, has no corresponding cache file". format(name)) sys.exit(1) else: # This is executed in a try-catch if there are no exceptions raised if mrnum == "": print("cache file for {} is empty".format(name))