Skip to content

Commit af3a1bb

Browse files
committed
Use prow from the pipelines-as-code-prow repo
We have now moved the pipeline the repository pipelines-as-code-prow. This commit updates the prow pipeline to use the new location. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent aae5564 commit af3a1bb

File tree

1 file changed

+19
-93
lines changed

1 file changed

+19
-93
lines changed

.tekton/prow.yaml

+19-93
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,23 @@ kind: PipelineRun
44
metadata:
55
name: prow-commands
66
annotations:
7-
pipelinesascode.tekton.dev/on-comment: "^/(help|(assign|unassign|label|unlabel)[ ].*)"
8-
pipelinesascode.tekton.dev/max-keep-runs: "5"
7+
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code-prow/refs/heads/main/pipeline-prow.yaml"
8+
pipelinesascode.tekton.dev/on-comment: "^/(help|lgtm|(assign|unassign|label|unlabel)[ ].*)$"
9+
pipelinesascode.tekton.dev/max-keep-runs: "2"
910
spec:
10-
pipelineSpec:
11-
tasks:
12-
- name: manage-pr
13-
displayName: Manage PR Assignments & Labels
14-
taskSpec:
15-
steps:
16-
- name: manage-pr
17-
image: registry.access.redhat.com/ubi9/ubi
18-
env:
19-
- name: GITHUB_TOKEN
20-
valueFrom:
21-
secretKeyRef:
22-
name: "{{ git_auth_secret }}"
23-
key: "git-provider-token"
24-
script: |
25-
#!/usr/bin/env python3
26-
import os
27-
import re
28-
import requests
29-
import sys
30-
31-
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
32-
if not GITHUB_TOKEN:
33-
print("❌ GITHUB_TOKEN environment variable is missing", file=sys.stderr)
34-
sys.exit(1)
35-
36-
API_BASE = "https://api.github.com/repos/{{ repo_owner }}/{{ repo_name }}/issues/{{ pull_request_number }}"
37-
HEADERS = {
38-
"Authorization": f"Bearer {GITHUB_TOKEN}",
39-
"Accept": "application/vnd.github.v3+json",
40-
"X-GitHub-Api-Version": "2022-11-28"
41-
}
42-
43-
COMMENT = """{{ trigger_comment }}"""
44-
match = re.match(r"^/(assign|unassign|label|unlabel|help)\s*(.*)", COMMENT)
45-
46-
if not match:
47-
print(f"⚠️ No valid command found in comment: {COMMENT}", file=sys.stderr)
48-
sys.exit(1)
49-
50-
command, values = match.groups()
51-
values = values.split()
52-
53-
def make_request(method, url, data=None):
54-
try:
55-
if method == "POST":
56-
response = requests.post(url, json=data, headers=HEADERS)
57-
elif method == "DELETE":
58-
response = requests.delete(url, json=data, headers=HEADERS)
59-
else:
60-
return None
61-
response.raise_for_status()
62-
return response
63-
except requests.exceptions.RequestException as e:
64-
print(f"❌ API request failed: {e}", file=sys.stderr)
65-
sys.exit(1)
66-
67-
if command == "assign" or command == "unassign":
68-
method = "POST" if command == "assign" else "DELETE"
69-
API_URL = f"{API_BASE.replace('issues', 'pulls')}/requested_reviewers"
70-
values = [value.lstrip('@') for value in values]
71-
data = {"reviewers": values}
72-
response = make_request(method, API_URL, data)
73-
elif command == "label":
74-
API_URL = f"{API_BASE}/labels"
75-
data = {"labels": values}
76-
response = make_request("POST", API_URL, data)
77-
elif command == "unlabel":
78-
API_URL = f"{API_BASE}/labels/{'/'.join(values)}"
79-
for label in values:
80-
response = make_request("DELETE", f"{API_BASE}/labels/{label}")
81-
elif command == "help":
82-
API_URL = f"{API_BASE}/comments"
83-
help_text = """### 🤖 Available Commands
84-
| Command | Description |
85-
|---------|-------------|
86-
| `/assign user1 user2` | Assigns users to the PR |
87-
| `/unassign user1 user2` | Removes assigned users |
88-
| `/label bug feature` | Adds labels to the PR |
89-
| `/unlabel bug feature` | Removes labels from the PR |
90-
| `/help` | Shows this help message |
91-
"""
92-
response = make_request("POST", API_URL, {"body": help_text})
93-
print(f"✅ Posted help message")
94-
sys.exit(0)
95-
96-
if response and response.status_code in [200, 201, 204]:
97-
print(f"✅ Successfully processed {command}: {', '.join(values) if values else ''}")
98-
else:
99-
print(f"❌ Failed to process {command}: {response.status_code if response else 'N/A'} - {response.text if response else 'N/A'}", file=sys.stderr)
100-
sys.exit(1)
11+
params:
12+
- name: trigger_comment
13+
value: |
14+
{{ trigger_comment }}
15+
- name: repo_owner
16+
value: "{{ repo_owner }}"
17+
- name: repo_name
18+
value: "{{ repo_name }}"
19+
- name: pull_request_number
20+
value: "{{ pull_request_number }}"
21+
- name: git_auth_secret
22+
value: "{{ git_auth_secret }}"
23+
- name: pull_request_sender
24+
value: "{{ body.issue.user.login }}"
25+
pipelineRef:
26+
name: prow-commands

0 commit comments

Comments
 (0)