-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close linked issues when a PR is merged #777
Labels
Comments
Pulling back because I want to do it, but
|
Demo script: import json
import requests
import psycopg2
s = requests.Session()
s.headers['Authorization'] =
with psycopg2.connect(dbname="mig") as cn:
with cn.cursor() as cr:
cr.execute("""
SELECT r.name, p.number
FROM forwardport_branch_remover br
LEFT JOIN runbot_merge_pull_requests p on p.id = br.pr_id
LEFT JOIN runbot_merge_repository r on r.id = p.repository
""")
prs = [
(*n.split('/'), p)
for n, p in cr
]
body = "".join(
"""
_%d: repository(owner: %s, name: %s) {
pullRequest(number: %d) {
closingIssuesReferences(last: 100) {
nodes {
number
}
}
}
}
""" % (i, json.dumps(o), json.dumps(r), n)
for i, (o, r, n) in enumerate(prs)
)
r = s.post(
'https://api.github.com/graphql',
json={'query': f"query {{\n{body}\n}}"}
)
print(r.headers['x-ratelimit-remaining'], '/', r.headers['x-ratelimit-limit'], r.headers['x-ratelimit-resource'])
for (owner, name, number), entry in zip(prs, r.json()['data'].values()):
if not entry['pullRequest']:
continue
refs = [
r['number']
for r in entry['pullRequest']['closingIssuesReferences'].get('nodes', ())
]
if refs:
print(f"{owner}/{name}#{number} =>")
for ref in refs:
r = s.get(f'https://api.github.com/repos/{owner}/{name}/issues/{ref}')
if r.ok:
i = r.json()
print(f'\t#{ref} {i["state"]} {i["state_reason"]}')
print('\t', r.headers['x-ratelimit-remaining'], '/', r.headers['x-ratelimit-limit'], r.headers['x-ratelimit-resource']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Github has features which close a linked issue when a PR is merged (possibly just to the main branch): special tags in commits (
closes
,fixes
, ...) or manually linked issues (to test how this behaves).In the context of the mergebot, and odoo's workflow, this is a problem:
It's possible to retrieve linked PRs but only in the v4 API via
PullRequest.closingIssuesReferences
. Though at least that looks pre-filtered by applicable issues (aka only those this PR will close). This means on merging a PR we could retrieve this list and close all the linked issues. A bit of a pain because GQL but it'd be done via a cron anyway (as we'd need to be sure the PR was successfully merged before even checking) so should be feasible via an ad-hoc GQL query.The text was updated successfully, but these errors were encountered: