Skip to content

Commit

Permalink
Merge pull request Codium-ai#428 from Codium-ai/tr/fixes
Browse files Browse the repository at this point in the history
Enhancements and Fixes in Bitbucket Provider
  • Loading branch information
mrT23 committed Nov 6, 2023
2 parents d59497c + c8768d6 commit 4d1055e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
15 changes: 5 additions & 10 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ There are several ways to use PR-Agent:

### 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:
```
Expand All @@ -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).


Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest:
If you want to ensure you're running a specific version of the Docker image, consider using the image's digest:
```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
```

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
```

---
Expand Down
28 changes: 28 additions & 0 deletions pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def __init__(
self.repo = None
self.pr_num = None
self.pr = None
self.pr_url = pr_url
self.temp_comments = []
self.incremental = incremental
self.diff_files = None
if pr_url:
self.set_pr(pr_url)
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"]["comments"]["href"]
Expand All @@ -44,6 +46,8 @@ def get_repo_settings(self):
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
f"{self.pr.destination_branch}/.pr_agent.toml")
response = requests.request("GET", url, headers=self.headers)
if response.status_code == 404: # not found
return ""
contents = response.text.encode('utf-8')
return contents
except Exception:
Expand Down Expand Up @@ -114,6 +118,9 @@ def get_files(self):
return [diff.new.path for diff in self.pr.diffstat()]

def get_diff_files(self) -> list[FilePatchInfo]:
if self.diff_files:
return self.diff_files

diffs = self.pr.diffstat()
diff_split = [
"diff --git%s" % x for x in self.pr.diff().split("diff --git") if x.strip()
Expand All @@ -133,6 +140,7 @@ def get_diff_files(self) -> list[FilePatchInfo]:
diff.new.path,
)
)
self.diff_files = diff_files
return diff_files

def publish_comment(self, pr_comment: str, is_temporary: bool = False):
Expand Down Expand Up @@ -181,6 +189,26 @@ def publish_inline_comment(self, comment: str, from_line: int, file: str):
)
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]):
for comment in comments:
self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _prepare_pr_answer(self) -> Tuple[str, str]:
for file in value:
filename = file['filename'].replace("'", "`")
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"):
pr_body +="</details>\n"
else:
Expand Down
13 changes: 0 additions & 13 deletions pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,6 @@ def _prepare_pr_review(self) -> str:
suggestion['relevant line'] = f"[{suggestion['relevant line']}]({link})"
else:
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
Expand Down

0 comments on commit 4d1055e

Please sign in to comment.