bin/gitlab_gql: resolve sha locally to be able to use things like HEAD

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26073>
This commit is contained in:
Eric Engestrom
2023-11-06 16:08:14 +00:00
committed by Marge Bot
parent 781e1a34cf
commit cc37af8fbc

View File

@@ -11,6 +11,7 @@ from dataclasses import dataclass, field
from itertools import accumulate from itertools import accumulate
from os import getenv from os import getenv
from pathlib import Path from pathlib import Path
from subprocess import check_output
from typing import Any, Iterable, Optional, Pattern, TypedDict, Union from typing import Any, Iterable, Optional, Pattern, TypedDict, Union
import yaml import yaml
@@ -471,7 +472,7 @@ def parse_args() -> Namespace:
formatter_class=ArgumentDefaultsHelpFormatter, formatter_class=ArgumentDefaultsHelpFormatter,
description="CLI and library with utility functions to debug jobs via Gitlab GraphQL", description="CLI and library with utility functions to debug jobs via Gitlab GraphQL",
epilog=f"""Example: epilog=f"""Example:
{Path(__file__).name} --rev $(git rev-parse HEAD) --print-job-dag""", {Path(__file__).name} --rev HEAD --print-job-dag""",
) )
parser.add_argument("-pp", "--project-path", type=str, default="mesa/mesa") parser.add_argument("-pp", "--project-path", type=str, default="mesa/mesa")
parser.add_argument("--sha", "--rev", type=str, required=True) parser.add_argument("--sha", "--rev", type=str, required=True)
@@ -505,7 +506,10 @@ def parse_args() -> Namespace:
def main(): def main():
args = parse_args() args = parse_args()
gl_gql = GitlabGQL(token=args.gitlab_token) gl_gql = GitlabGQL(token=args.gitlab_token)
args.iid = from_sha_to_pipeline_iid(gl_gql, {"projectPath": args.project_path, "sha": args.sha})
sha = check_output(['git', 'rev-parse', args.sha]).decode('ascii').strip()
args.iid = from_sha_to_pipeline_iid(gl_gql, {"projectPath": args.project_path, "sha": sha})
if args.print_dag: if args.print_dag:
dag = create_job_needs_dag( dag = create_job_needs_dag(
@@ -519,16 +523,16 @@ def main():
if args.print_merged_yaml: if args.print_merged_yaml:
print( print(
fetch_merged_yaml( fetch_merged_yaml(
gl_gql, {"projectPath": args.project_path, "sha": args.sha} gl_gql, {"projectPath": args.project_path, "sha": sha}
) )
) )
if args.print_job_manifest: if args.print_job_manifest:
merged_yaml = fetch_merged_yaml( merged_yaml = fetch_merged_yaml(
gl_gql, {"projectPath": args.project_path, "sha": args.sha} gl_gql, {"projectPath": args.project_path, "sha": sha}
) )
get_job_final_definition( get_job_final_definition(
args.print_job_manifest, merged_yaml, args.project_path, args.sha args.print_job_manifest, merged_yaml, args.project_path, sha
) )