def test_queue_name_migration(): r = utils.get_redis_for_cache() r.flushall() r.set( "strict-merge-config~12345~owner~repo~1", json.dumps({"fake": "config1"}), ) r.set( "strict-merge-config~12345~owner~repo~2", json.dumps({"fake": "config2"}), ) r.set( "strict-merge-config~12345~owner~repo~3", json.dumps({"fake": "config3"}), ) r.set( "strict-merge-config~54321~foo~bar~42", json.dumps({"fake": "config42"}), ) r.zadd("strict-merge-queues~12345~owner~repo~master", {1: 1000}) r.zadd("strict-merge-queues~12345~owner~repo~stable", {2: 2000}) r.zadd("strict-merge-queues~12345~owner~repo~master", {3: 5000}) r.zadd("strict-merge-queues~54321~foo~bar~yo", {42: 5000}) queue.Queue(r, owner_id=12, owner="owner", repo_id=34, repo="repo", ref="master") queue.Queue(r, owner_id=4, owner="foo", repo_id=2, repo="bar", ref="whatever") assert r.keys("strict-*") == [] assert sorted(r.keys("merge-queue~*")) == [ "merge-queue~12~34~master", "merge-queue~12~34~stable", "merge-queue~4~2~yo", ] assert sorted(r.keys("merge-config~*")) == [ "merge-config~12~34~1", "merge-config~12~34~2", "merge-config~12~34~3", "merge-config~4~2~42", ] r.flushall()
def report( url: str, ) -> typing.Union[context.Context, github.GithubInstallationClient, None]: path = url.replace("https://github.com/", "") pull_number: typing.Optional[str] repo: typing.Optional[str] try: owner, repo, _, pull_number = path.split("/") except ValueError: pull_number = None try: owner, repo = path.split("/") except ValueError: owner = path repo = None try: client = github.get_client(owner) except exceptions.MergifyNotInstalled: print(f"* Mergify is not installed on account {owner}") return None # Do a dumb request just to authenticate client.get("/") if client.auth.installation is None: print("No installation detected") return None print("* INSTALLATION ID: %s" % client.auth.installation["id"]) if client.auth.owner_id is None: raise RuntimeError("Unable to get owner_id") cached_sub, db_sub = utils.async_run( subscription.Subscription.get_subscription(client.auth.owner_id), subscription.Subscription._retrieve_subscription_from_db(client.auth.owner_id), ) if repo is None: slug = None else: slug = owner + "/" + repo print("* SUBSCRIBED (cache/db): %s / %s" % (cached_sub.active, db_sub.active)) print("* Features (cache):") for f in cached_sub.features: print(f" - {f.value}") report_sub(client.auth.installation["id"], cached_sub, "ENGINE-CACHE", slug) report_sub(client.auth.installation["id"], db_sub, "DASHBOARD", slug) utils.async_run(report_worker_status(client.auth.owner)) if repo is not None: repo_info = client.item(f"/repos/{owner}/{repo}") print(f"* REPOSITORY IS {'PRIVATE' if repo_info['private'] else 'PUBLIC'}") print("* CONFIGURATION:") mergify_config = None try: filename, mergify_config_content = rules.get_mergify_config_content( client, repo ) except rules.NoRules: # pragma: no cover print(".mergify.yml is missing") else: print(f"Config filename: {filename}") print(mergify_config_content.decode()) try: mergify_config = rules.UserConfigurationSchema(mergify_config_content) except rules.InvalidRules as e: # pragma: no cover print("configuration is invalid %s" % str(e)) else: mergify_config["pull_request_rules"].rules.extend( engine.DEFAULT_PULL_REQUEST_RULES.rules ) if pull_number is None: for branch in typing.cast( typing.List[github_types.GitHubBranch], client.items(f"/repos/{owner}/{repo}/branches"), ): q = queue.Queue( utils.get_redis_for_cache(), repo_info["owner"]["id"], repo_info["owner"]["login"], repo_info["id"], repo_info["name"], branch["name"], ) pulls = q.get_pulls() if not pulls: continue print(f"* QUEUES {branch['name']}:") for priority, grouped_pulls in itertools.groupby( pulls, key=lambda v: q.get_config(v)["priority"] ): try: fancy_priority = merge_base.PriorityAliases(priority).name except ValueError: fancy_priority = str(priority) formatted_pulls = ", ".join((f"#{p}" for p in grouped_pulls)) print(f"** {formatted_pulls} (priority: {fancy_priority})") else: pull_raw = client.item(f"/repos/{owner}/{repo}/pulls/{pull_number}") ctxt = context.Context( client, pull_raw, cached_sub, [], ) # FIXME queues could also be printed if no pull number given q = queue.Queue.from_context(ctxt) print("* QUEUES: %s" % ", ".join([f"#{p}" for p in q.get_pulls()])) print("* PULL REQUEST:") pr_data = dict(ctxt.pull_request.items()) pprint.pprint(pr_data, width=160) print("is_behind: %s" % ctxt.is_behind) print("mergeable_state: %s" % ctxt.pull["mergeable_state"]) print("* MERGIFY LAST CHECKS:") for c in ctxt.pull_engine_check_runs: print( "[%s]: %s | %s" % (c["name"], c["conclusion"], c["output"].get("title")) ) print( "> " + "\n> ".join( ("No Summary",) if c["output"]["summary"] is None else c["output"]["summary"].split("\n") ) ) if mergify_config is not None: print("* MERGIFY LIVE MATCHES:") match = mergify_config["pull_request_rules"].get_pull_request_rule(ctxt) summary_title, summary = actions_runner.gen_summary(ctxt, match) print("> %s" % summary_title) print(summary) return ctxt return client