Skip to content

Commit

Permalink
Add task to print pr state (#32806)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelianR authored Jan 9, 2025
1 parent d00e512 commit 1deb401
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tasks/github_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import os
import re
import time
Expand Down Expand Up @@ -639,3 +640,32 @@ def check_qa_labels(_, labels: str):
if len(qa_labels) > 1:
raise Exit(f"More than one QA label set.\n{docs}", code=1)
print("QA label set correctly")


@task
def print_pr_state(_, id):
"""Print the PR merge state if the PR is stuck within the merge queue."""

from tasks.libs.ciproviders.github_api import GithubAPI

query = """
query {
repository (owner: "DataDog", name: "datadog-agent") {
pullRequest(number: ID) {
reviewDecision
state
statusCheckRollup {
state
}
mergeable
mergeStateStatus
locked
}
}
}
""".replace("ID", id) # Use replace to avoid formatting issues with curly braces

gh = GithubAPI()
res = gh.graphql(query)

print(json.dumps(res, indent=2))
16 changes: 16 additions & 0 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ def repo(self):

return self._repository

def graphql(self, query):
"""
Perform a GraphQL query against the Github API.
"""

headers = {"Authorization": "Bearer " + self._auth.token, "Content-Type": "application/json"}
res = requests.post(
"https://api.github.com/graphql",
headers=headers,
json={"query": query},
)
if res.status_code == 200:
return res.json()
else:
raise RuntimeError(f"Failed to query Github: {res.text}")

def get_branch(self, branch_name):
"""
Gets info on a given branch in the given Github repository.
Expand Down

0 comments on commit 1deb401

Please sign in to comment.