MCPcopy Create free account
hub / github.com/ceph/ceph / _execute_pull_request

Method _execute_pull_request

src/script/redmine-upkeep.py:1273–1365  ·  view source on GitHub ↗

Handles the --pull-request logic. 1. Finds Redmine issues linked to the PR and runs transforms on them. 2. If none, inspects the local merge commit for "Fixes:" tags. 3. If tags are found, comments on the GH PR to ask the author to link the ticket.

(self)

Source from the content-addressed store, hash-verified

1271 self._execute_filters()
1272
1273 def _execute_pull_request(self):
1274 """
1275 Handles the --pull-request logic.
1276 1. Finds Redmine issues linked to the PR and runs transforms on them.
1277 2. If none, inspects the local merge commit for "Fixes:" tags.
1278 3. If tags are found, comments on the GH PR to ask the author to link the ticket.
1279 """
1280 pr_id = self.pull_request_id
1281 merge_commit_sha = self.merge_commit
1282 log.info(f"Querying Redmine for issues linked to PR #{pr_id} and merge commit {merge_commit_sha}")
1283
1284 filters = {
1285 "project_id": self.project_id,
1286 "status_id": "*",
1287 f"cf_{REDMINE_CUSTOM_FIELD_ID_PULL_REQUEST_ID}": pr_id,
1288 }
1289 issues = self.R.issue.filter(**filters)
1290
1291 processed_issue_ids = set()
1292 is_backport_pr = False
1293
1294 if len(issues) > 0:
1295 log.info(f"Found {len(issues)} linked issue(s). Applying transformations.")
1296 for issue in issues:
1297 if issue.tracker.id == REDMINE_TRACKER_ID_BACKPORT:
1298 is_backport_pr = True
1299 self._process_issue_transformations(issue)
1300 processed_issue_ids.add(issue.id)
1301 # Still, check commit logs.
1302 else:
1303 log.warning(f"No Redmine issues found linked to PR #{pr_id}. Inspecting local merge commit {merge_commit_sha} for 'Fixes:' tags.")
1304
1305 found_tracker_ids = set()
1306 try:
1307 revrange = f"{merge_commit_sha}^..{merge_commit_sha}"
1308 log.info(f"Iterating commits {revrange}")
1309 for commit in self.G.iter_commits(revrange):
1310 log.info(f"Inspecting commit {commit.hexsha}")
1311
1312 fixes_regex = re.compile(r"Fixes: https://tracker.ceph.com/issues/(\d+)", re.MULTILINE)
1313 commit_fixes = set(fixes_regex.findall(commit.message))
1314 for tracker_id in commit_fixes:
1315 try:
1316 t_id = int(tracker_id)
1317
1318 # If this is a backport PR, ignore "Fixes:" tags pointing to main trackers
1319 if is_backport_pr:
1320 referenced_issue = self.R.issue.get(t_id)
1321 if referenced_issue.tracker.id != REDMINE_TRACKER_ID_BACKPORT:
1322 log.info(f"Ignoring 'Fixes:' tag for main tracker #{t_id} in backport PR context.")
1323 continue
1324
1325 log.info(f"Commit {commit.hexsha} claims to fix https://tracker.ceph.com/issues/{t_id}")
1326 found_tracker_ids.add(t_id)
1327 except Exception as e:
1328 log.warning(f"Could not verify tracker #{tracker_id}: {e}")
1329 # Fallback to adding it if verification fails just in case
1330 found_tracker_ids.add(int(tracker_id))

Callers 1

Calls 13

post_github_commentFunction · 0.85
setFunction · 0.50
infoMethod · 0.45
filterMethod · 0.45
addMethod · 0.45
warningMethod · 0.45
compileMethod · 0.45
getMethod · 0.45
errorMethod · 0.45
debugMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected