Skip to content

Commit 5f515b9

Browse files
chmoueltheakshaypant
authored andcommitted
feat: Move pr-ci scripts to be executable with uv
The pr-ci scripts were refactored to be directly executable with `uv run`. This change removes the need for a separate `pyproject.toml` and `uv.lock` file, simplifying dependency management and allowing for easier execution of the scripts. The internal imports were updated to reflect the new file structure. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent a541f27 commit 5f515b9

15 files changed

Lines changed: 58 additions & 664 deletions

File tree

.tekton/issue-create.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ spec:
8181
- name: GEMINI_MODEL
8282
value: "$(params.gemini_model)"
8383
script: |
84-
uv run --directory ./hack/pr-ci pr-ci issue-create
84+
uv run --directory ./hack/pr-ci main.py issue-create
8585
params:
8686
- name: repo_url
8787
value: "$(params.repo_url)"

.tekton/jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ spec:
110110
- name: JIRA_ISSUETYPE
111111
value: "$(params.jira_issuetype)"
112112
script: |
113-
uv run --directory ./hack/pr-ci pr-ci jira-create
113+
uv run --directory ./hack/pr-ci main.py jira-create
114114
params:
115115
- name: repo_url
116116
value: "$(params.repo_url)"

.tekton/pr-ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ spec:
8787
- name: PR_NUMBER
8888
value: "$(params.pull_request_number)"
8989
script: |
90-
uv run --directory ./hack/pr-ci pr-ci lint
90+
uv run --directory ./hack/pr-ci main.py lint
9191
- name: analyze-and-label
9292
image: ghcr.io/astral-sh/uv:debian
9393
workingDir: $(workspaces.source.path)
@@ -117,7 +117,7 @@ spec:
117117
- name: MAX_LABELS
118118
value: "$(params.max_labels)"
119119
script: |
120-
uv run --directory ./hack/pr-ci pr-ci update
120+
uv run --directory ./hack/pr-ci main.py update
121121
params:
122122
- name: repo_url
123123
value: "$(params.repo_url)"

hack/pr-ci/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ A Python package that provides automated PR (Pull Request) analysis and enhancem
3232

3333
```bash
3434
# Run all checks (lint + update)
35-
uv run pr-ci all
35+
uv run main.py all
3636

3737
# Run only linting checks
38-
uv run pr-ci lint
38+
uv run main.py lint
3939

4040
# Run only label updates
41-
uv run pr-ci update
41+
uv run main.py update
4242

4343
# Generate GitHub issue content
44-
uv run pr-ci issue-create
44+
uv run main.py issue-create
4545
```
4646

4747
### Environment Variables
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from typing import Optional
66

77
import requests
8-
9-
from .github import GitHubClient
8+
from github import GitHubClient
109

1110
PR_TITLE_COMMENT_MARKER = "<!-- pr-title-lint -->"
1211

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
"""Analyzes PR content using Gemini AI to suggest labels."""
1+
"Analyzes PR content using Gemini AI to suggest labels."
22

33
from __future__ import annotations
44

55
import json
66
from typing import List
77

8-
import google.generativeai as genai
9-
10-
from .config import DEFAULT_MODEL
11-
from .pr_data import PRData
8+
from google import genai
9+
from config import DEFAULT_MODEL
10+
from pr_data import PRData
1211

1312

1413
class GeminiAnalyzer:
1514
"""Analyzes PR content using Gemini AI to suggest labels."""
1615

1716
def __init__(self, api_key: str, model_name: str = DEFAULT_MODEL):
18-
genai.configure(api_key=api_key)
19-
self.model = genai.GenerativeModel(model_name)
17+
self.client = genai.Client(api_key=api_key)
2018
self.model_name = model_name
2119

2220
def suggest_labels(
@@ -28,7 +26,9 @@ def suggest_labels(
2826
"""Analyze PR and suggest appropriate labels."""
2927
try:
3028
prompt = self._build_prompt(pr_data, available_labels, excluded_labels)
31-
response = self.model.generate_content(prompt)
29+
response = self.client.models.generate_content(
30+
model=self.model_name, contents=prompt
31+
)
3232
return self._parse_response(response)
3333
except Exception as exc: # pylint: disable=broad-except
3434
print(f"Error with Gemini API: {exc}")
@@ -106,15 +106,16 @@ class GeminiIssueGenerator:
106106
"""Generates GitHub issue content using Gemini AI."""
107107

108108
def __init__(self, api_key: str, model_name: str = DEFAULT_MODEL):
109-
genai.configure(api_key=api_key)
110-
self.model = genai.GenerativeModel(model_name)
109+
self.client = genai.Client(api_key=api_key)
111110
self.model_name = model_name
112111

113112
def generate_issue(self, pr_data: PRData) -> dict:
114113
"""Analyze PR and generate GitHub issue content."""
115114
try:
116115
prompt = self._build_prompt(pr_data)
117-
response = self.model.generate_content(prompt)
116+
response = self.client.models.generate_content(
117+
model=self.model_name, contents=prompt
118+
)
118119
return self._parse_response(response)
119120
except Exception as exc: # pylint: disable=broad-except
120121
print(f"Error with Gemini API: {exc}")
@@ -154,7 +155,7 @@ def _build_prompt(self, pr_data: PRData) -> str:
154155
Example for a bug fix PR:
155156
{{
156157
"title": "Bug: User authentication fails when tokens expire",
157-
"body": "### Problem Description\\n\\nUsers are experiencing authentication failures when their session tokens expire, causing them to lose their work and get logged out unexpectedly.\\n\\n### Current Behavior\\n\\nWhen a token expires, the application throws an error and immediately logs the user out without any warning or graceful handling.\\n\\n### Expected Behavior\\n\\nThe application should detect token expiration and either automatically refresh the token or provide a clear warning to the user before logging them out.\\n\\n### Additional Context\\n\\nThis affects user experience significantly as users lose unsaved work when tokens expire during active sessions."
158+
"body": "### Problem Description\n\nUsers are experiencing authentication failures when their session tokens expire, causing them to lose their work and get logged out unexpectedly.\n\n### Current Behavior\n\nWhen a token expires, the application throws an error and immediately logs the user out without any warning or graceful handling.\n\n### Expected Behavior\n\nThe application should detect token expiration and either automatically refresh the token or provide a clear warning to the user before logging them out.\n\n### Additional Context\n\nThis affects user experience significantly as users lose unsaved work when tokens expire during active sessions."
158159
}}
159160
160161
Respond with only valid JSON.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from typing import List, Optional, Sequence
66

77
import requests
8-
9-
from .config import Config
8+
from config import Config
109

1110
GITHUB_API_BASE = "https://api.github.com"
1211

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import json
66
from typing import Any, Dict, Optional
77

8-
import google.generativeai as genai
8+
from google import genai
99
import requests
10-
11-
from .config import Config, DEFAULT_MODEL
12-
from .pr_data import PRData
10+
from config import DEFAULT_MODEL, Config
11+
from pr_data import PRData
1312

1413

1514
class JiraClient:
@@ -69,12 +68,13 @@ class GeminiJiraGenerator:
6968

7069
def __init__(self, api_key: str, model_name: str = DEFAULT_MODEL):
7170
"""Initialize with Gemini credentials."""
72-
genai.configure(api_key=api_key)
73-
self.model = genai.GenerativeModel(model_name)
71+
self.client = genai.Client(api_key=api_key)
7472
self.model_name = model_name
7573

7674
def generate_jira_ticket(
77-
self, pr_data: PRData, user_query: str = ""
75+
self,
76+
pr_data: PRData,
77+
user_query: str = "",
7878
) -> Optional[Dict[str, str]]:
7979
"""Generate JIRA ticket content for a PR."""
8080
# Use SRVKP JIRA template from the project rules
@@ -181,7 +181,9 @@ def generate_jira_ticket(
181181
Respond only with the JSON object."""
182182

183183
try:
184-
response = self.model.generate_content(prompt)
184+
response = self.client.models.generate_content(
185+
model=self.model_name, contents=prompt
186+
)
185187
if not response:
186188
return None
187189

@@ -259,7 +261,7 @@ def _format_commits(self, commits: list[str]) -> str:
259261
return "No commits available"
260262

261263
formatted = []
262-
for commit in commits[-5:]: # Last 5 commits
264+
for commit in commits[-5:]:
263265
# Truncate long commit messages
264266
if len(commit) > 100:
265267
commit = commit[:97] + "..."
@@ -291,7 +293,9 @@ def generate_release_note(self, pr_data: PRData) -> Optional[str]:
291293
Generate a release note that clearly communicates the value of this change to end users. Respond with only the release note text, no additional formatting or explanation."""
292294

293295
try:
294-
response = self.model.generate_content(prompt)
296+
response = self.client.models.generate_content(
297+
model=self.model_name, contents=prompt
298+
)
295299
if not response:
296300
return None
297301

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from pathlib import Path
88
from typing import List, Optional, Tuple
99

10-
from .comments import PR_TITLE_COMMENT_MARKER, CommentManager
11-
from .github import GitHubClient
12-
from .pr_data import PRData
10+
from comments import PR_TITLE_COMMENT_MARKER, CommentManager
11+
from github import GitHubClient
12+
from pr_data import PRData
1313

1414
DEFAULT_JIRA_PROJECT = r"(SRVKP|KONFLUX)"
1515
MIN_DESCRIPTION_LINES = 3

0 commit comments

Comments
 (0)