mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
Merge pull request #428 from Codium-ai/tr/fixes
Enhancements and Fixes in Bitbucket Provider
This commit is contained in:
15
INSTALL.md
15
INSTALL.md
@ -29,7 +29,9 @@ There are several ways to use PR-Agent:
|
|||||||
|
|
||||||
### Use Docker image (no installation required)
|
### Use Docker image (no installation required)
|
||||||
|
|
||||||
To request a review for a PR, or ask a question about a PR, you can run directly from the Docker image. Here's how:
|
A list of the relevant tools can be found in the [tools guide](./docs/TOOLS_GUIDE.md).
|
||||||
|
|
||||||
|
To invoke a tool (for example `review`), you can run directly from the Docker image. Here's how:
|
||||||
|
|
||||||
- For GitHub:
|
- For GitHub:
|
||||||
```
|
```
|
||||||
@ -55,22 +57,15 @@ For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Similarly, to ask a question about a PR, run the following command:
|
|
||||||
```
|
|
||||||
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent --pr_url <pr_url> ask "<your question>"
|
|
||||||
```
|
|
||||||
|
|
||||||
A list of the relevant tools can be found in the [tools guide](./docs/TOOLS_GUIDE.md).
|
If you want to ensure you're running a specific version of the Docker image, consider using the image's digest:
|
||||||
|
|
||||||
|
|
||||||
Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest:
|
|
||||||
```bash
|
```bash
|
||||||
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url <pr_url> review
|
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url <pr_url> review
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can run a [specific released versions](./RELEASE_NOTES.md) of pr-agent, for example:
|
Or you can run a [specific released versions](./RELEASE_NOTES.md) of pr-agent, for example:
|
||||||
```
|
```
|
||||||
codiumai/pr-agent@v0.8
|
codiumai/pr-agent@v0.9
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -32,8 +32,10 @@ class BitbucketProvider(GitProvider):
|
|||||||
self.repo = None
|
self.repo = None
|
||||||
self.pr_num = None
|
self.pr_num = None
|
||||||
self.pr = None
|
self.pr = None
|
||||||
|
self.pr_url = pr_url
|
||||||
self.temp_comments = []
|
self.temp_comments = []
|
||||||
self.incremental = incremental
|
self.incremental = incremental
|
||||||
|
self.diff_files = None
|
||||||
if pr_url:
|
if pr_url:
|
||||||
self.set_pr(pr_url)
|
self.set_pr(pr_url)
|
||||||
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"]["comments"]["href"]
|
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"]["comments"]["href"]
|
||||||
@ -44,6 +46,8 @@ class BitbucketProvider(GitProvider):
|
|||||||
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
|
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
|
||||||
f"{self.pr.destination_branch}/.pr_agent.toml")
|
f"{self.pr.destination_branch}/.pr_agent.toml")
|
||||||
response = requests.request("GET", url, headers=self.headers)
|
response = requests.request("GET", url, headers=self.headers)
|
||||||
|
if response.status_code == 404: # not found
|
||||||
|
return ""
|
||||||
contents = response.text.encode('utf-8')
|
contents = response.text.encode('utf-8')
|
||||||
return contents
|
return contents
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -114,6 +118,9 @@ class BitbucketProvider(GitProvider):
|
|||||||
return [diff.new.path for diff in self.pr.diffstat()]
|
return [diff.new.path for diff in self.pr.diffstat()]
|
||||||
|
|
||||||
def get_diff_files(self) -> list[FilePatchInfo]:
|
def get_diff_files(self) -> list[FilePatchInfo]:
|
||||||
|
if self.diff_files:
|
||||||
|
return self.diff_files
|
||||||
|
|
||||||
diffs = self.pr.diffstat()
|
diffs = self.pr.diffstat()
|
||||||
diff_split = [
|
diff_split = [
|
||||||
"diff --git%s" % x for x in self.pr.diff().split("diff --git") if x.strip()
|
"diff --git%s" % x for x in self.pr.diff().split("diff --git") if x.strip()
|
||||||
@ -133,6 +140,7 @@ class BitbucketProvider(GitProvider):
|
|||||||
diff.new.path,
|
diff.new.path,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.diff_files = diff_files
|
||||||
return diff_files
|
return diff_files
|
||||||
|
|
||||||
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
||||||
@ -181,6 +189,26 @@ class BitbucketProvider(GitProvider):
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def generate_link_to_relevant_line_number(self, suggestion) -> str:
|
||||||
|
try:
|
||||||
|
relevant_file = suggestion['relevant file'].strip('`').strip("'")
|
||||||
|
relevant_line_str = suggestion['relevant line']
|
||||||
|
if not relevant_line_str:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
diff_files = self.get_diff_files()
|
||||||
|
position, absolute_position = find_line_number_of_relevant_line_in_file \
|
||||||
|
(diff_files, relevant_file, relevant_line_str)
|
||||||
|
|
||||||
|
if absolute_position != -1 and self.pr_url:
|
||||||
|
link = f"{self.pr_url}/#L{relevant_file}T{absolute_position}"
|
||||||
|
return link
|
||||||
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
|
get_logger().info(f"Failed adding line link, error: {e}")
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
def publish_inline_comments(self, comments: list[dict]):
|
def publish_inline_comments(self, comments: list[dict]):
|
||||||
for comment in comments:
|
for comment in comments:
|
||||||
self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
|
self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
|
||||||
|
@ -248,7 +248,7 @@ class PRDescription:
|
|||||||
for file in value:
|
for file in value:
|
||||||
filename = file['filename'].replace("'", "`")
|
filename = file['filename'].replace("'", "`")
|
||||||
description = file['changes in file']
|
description = file['changes in file']
|
||||||
pr_body += f'`{filename}`: {description}\n'
|
pr_body += f'- `{filename}`: {description}\n'
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
pr_body +="</details>\n"
|
pr_body +="</details>\n"
|
||||||
else:
|
else:
|
||||||
|
@ -217,19 +217,6 @@ class PRReviewer:
|
|||||||
suggestion['relevant line'] = f"[{suggestion['relevant line']}]({link})"
|
suggestion['relevant line'] = f"[{suggestion['relevant line']}]({link})"
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# try:
|
|
||||||
# relevant_file = suggestion['relevant file'].strip('`').strip("'")
|
|
||||||
# relevant_line_str = suggestion['relevant line']
|
|
||||||
# if not relevant_line_str:
|
|
||||||
# return ""
|
|
||||||
#
|
|
||||||
# position, absolute_position = find_line_number_of_relevant_line_in_file(
|
|
||||||
# self.git_provider.diff_files, relevant_file, relevant_line_str)
|
|
||||||
# if absolute_position != -1:
|
|
||||||
# suggestion[
|
|
||||||
# 'relevant line'] = f"{suggestion['relevant line']} (line {absolute_position})"
|
|
||||||
# except:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
# Add incremental review section
|
# Add incremental review section
|
||||||
|
Reference in New Issue
Block a user