Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AI-github-demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Iswarabhotla Sunder
AI-github-demo
Commits
0be3c3e0
Commit
0be3c3e0
authored
Nov 27, 2024
by
Iswarabhotla Sunder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
This is a new file
parent
255b6940
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
PineCodeIntegration.py
PineCodeIntegration.py
+97
-0
No files found.
PineCodeIntegration.py
0 → 100644
View file @
0be3c3e0
import
os
import
requests
from
pinecone
import
Pinecone
,
ServerlessSpec
import
re
import
pinecone
# Ensure to import pinecone correctly
# Initialize Pinecone instance with your API key
pc
=
Pinecone
(
api_key
=
"pcsk_5L6s57_QRcqx63DUvLEk7bzohW7aYCuLChYPVZH9PX55sw49f2Uyt2CHqSGE9ERPGPBwnE"
,
environment
=
"us-east-1-gcp"
)
# Specify the environment if needed (e.g., "us-west1-gcp")
# Function to fetch pull request details from GitHub
def
get_pull_requests
(
repo_owner
,
repo_name
):
pull_requests_url
=
f
"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls"
print
(
pull_requests_url
)
response
=
requests
.
get
(
pull_requests_url
)
if
response
.
status_code
==
200
:
pull_requests
=
response
.
json
()
for
pr
in
pull_requests
:
pr_number
=
pr
[
'number'
]
pr_title
=
pr
[
'title'
]
pr_owner
=
pr
[
'user'
][
'login'
]
# PR owner
reviewer_comments
=
get_review_comments
(
repo_owner
,
repo_name
,
pr_number
)
store_in_pinecone
(
pr_number
,
pr_title
,
pr_owner
,
reviewer_comments
)
else
:
print
(
f
"Failed to fetch pull requests: {response.status_code}"
)
print
(
f
"Response: {response.text}"
)
# Function to fetch review comments for a pull request
def
get_review_comments
(
repo_owner
,
repo_name
,
pr_number
):
comments_url
=
f
"https://api.github.com/repos/{repo_owner}/{repo_name}/merge-requests/{pr_number}/comments"
response
=
requests
.
get
(
comments_url
)
comments
=
[]
if
response
.
status_code
==
200
:
review_comments
=
response
.
json
()
for
comment
in
review_comments
:
comment_author
=
comment
[
'user'
][
'login'
]
comment_body
=
comment
[
'body'
]
comments
.
append
({
'author'
:
comment_author
,
'body'
:
comment_body
})
else
:
print
(
f
"Failed to fetch comments for PR #{pr_number}: {response.status_code}"
)
return
comments
# Function to sanitize and create index name
def
create_pinecone_index
(
pr_number
):
index_name
=
f
"pr-{pr_number}"
.
lower
()
# Ensure the index name is lowercase
index_name
=
re
.
sub
(
r'[^a-z0-9-]'
,
'-'
,
index_name
)
# Replace non-alphanumeric characters with hyphens
# Check if index already exists
if
index_name
not
in
pc
.
list_indexes
()
.
names
():
pc
.
create_index
(
name
=
index_name
,
dimension
=
1536
,
# Modify this based on your data's dimensionality
metric
=
'euclidean'
,
# You can also use cosine or others
spec
=
ServerlessSpec
(
cloud
=
'aws'
,
region
=
'us-east-1'
)
)
return
index_name
# Function to store PR details in Pinecone
def
store_in_pinecone
(
pr_number
,
pr_title
,
pr_owner
,
reviewer_comments
):
# Constructing the data to be stored in Pinecone
index_name
=
create_pinecone_index
(
pr_number
)
# Store each reviewer comment along with the PR info
pr_data
=
[]
for
comment
in
reviewer_comments
:
reviewer_name
=
comment
[
'author'
]
comment_body
=
comment
[
'body'
]
pr_data
.
append
({
"pr_number"
:
pr_number
,
"pr_title"
:
pr_title
,
"pr_owner"
:
pr_owner
,
"reviewer_name"
:
reviewer_name
,
# Adding reviewer name
"comment_body"
:
comment_body
# Store individual comments
})
# Accessing the created index using Pinecone Index class
index
=
pinecone
.
Index
(
index_name
,
host
=
"us-east-1-gcp.pinecone.io"
)
# Specify the host URL for your environment
# Insert PR data into Pinecone (you'll typically convert it to vectors, here we store raw data)
for
pr
in
pr_data
:
pr_vector
=
[
float
(
pr_number
)]
# Ensure the vector data is of type float
index
.
upsert
(
vectors
=
[(
str
(
pr_number
),
pr_vector
,
pr
)])
# Upsert the data
print
(
f
"Stored PR #{pr_number} and comment from {pr_data[0]['reviewer_name']} in Pinecone."
)
# Main function to start fetching PRs
def
main
():
# Replace with your GitHub repo owner and name
repo_owner
=
"isunder"
# GitHub username or organization name
repo_name
=
"ai-github-demo"
# Repository name
get_pull_requests
(
repo_owner
,
repo_name
)
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment