Skip to content

Title for Branch1 PR #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Analyze Pull Request

on:
pull_request:
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened, edited]
branches:
- branch1

jobs:
analyze:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi, from branch1
38 changes: 0 additions & 38 deletions analyze_pr.py

This file was deleted.

1 change: 1 addition & 0 deletions hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
print("Hello World!")
print("writing from branch1")
167 changes: 167 additions & 0 deletions scripts/analyze_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import requests
import json
import os

class GitHubPR:
def __init__(self, owner, repo, pr_number, token):
self.owner = owner
self.repo = repo
self.pr_number = pr_number
self.headers = {
'Authorization': f'token {token}',
'Accept': 'application/vnd.github.v3+json'
}
self.base_url = f'https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}'

def get_pr_overview(self):
url = self.base_url
print(f"in pr overview, url:{url}")
response = requests.get(url, headers=self.headers)
print(f"in pr overview, url:{url}, response:{response}")
if response.status_code == 200:
pr_data = response.json()
return {
'number': pr_data['number'],
'title': pr_data['title'],
'body': pr_data['body']
}
else:
return None

def get_pr_details(self):
print("in pr details")
url = f'{self.base_url}/{self.pr_number}'
response = requests.get(url, headers=self.headers)
if response.status_code == 200:
return response.json()
else:
return None
r
def get_pr_files(self):
print("in files")
url = f'{self.base_url}/files'
response = requests.get(url, headers=self.headers)
print(f"in files, url:{url}, response:{response}")
if response.status_code == 200:
return response.json()
else:
return None

def get_pr_changes(self):
url = self.base_url
response = requests.get(url, headers=self.headers)
if response.status_code == 200:
pr_data = response.json()
return {
'additions': pr_data['additions'],
'deletions': pr_data['deletions'],
'changed_files': pr_data['changed_files']
}
else:
return None

def get_pr_reviews(self):
print("in reviews")
url = f'{self.base_url}/reviews'
response = requests.get(url, headers=self.headers)
print(f"in reviews, url:{url}, response:{response}")
if response.status_code == 200:
return response.json()
else:
return None

def get_pr_comments(self):
url = f'{self.base_url}/comments'
response = requests.get(url, headers=self.headers)
if response.status_code == 200:
return response.json()
else:
return None

def get_pr_info(self):
"""
Fetches and returns a dictionary containing all available information about the pull request,
including overview, files, changes, reviews, and comments.
"""
pr_info = {}

# PR Overview
pr_overview = self.get_pr_overview()
if pr_overview:
pr_info['overview'] = pr_overview
else:
pr_info['overview'] = None

# # PR Files
# pr_files = self.get_pr_files()
# if pr_files:
# pr_info['files'] = pr_files
# else:
# pr_info['files'] = None

# # PR Changes
# pr_changes = self.get_pr_changes()
# if pr_changes:
# pr_info['changes'] = pr_changes
# else:
# pr_info['changes'] = None

# # PR Reviews
# pr_reviews = self.get_pr_reviews()
# if pr_reviews:
# pr_info['reviews'] = pr_reviews
# else:
# pr_info['reviews'] = None

# # PR Comments
# pr_comments = self.get_pr_comments()
# if pr_comments:
# pr_info['comments'] = pr_comments
# else:
# pr_info['comments'] = None

return pr_info

def save_pr_info(pr_data, filename):
"""
Saves the provided PR information dictionary (`pr_data`)
"""
with open(filename, 'w') as outfile:
json.dump(pr_data, outfile, indent=4)

def save_swe_json(swe_json_data, filename):
"""
Saves the SWE args data given to swe-agent as json file
"""
with open(filename, 'w') as outfile:
json.dump(swe_json_data, outfile, indent=4)

def main():
# repo_url = os.getenv("GITHUB_REPOSITORY")
# pr_number = os.getenv("PR_NUMBER")
token = os.getenv("GITHUB_TOKEN")
repo_url = "icoding1010/my-test-project"
pr_number = 1
# token = my_token
owner, repo = repo_url.split("/")[-2], repo_url.split("/")[-1]

github_pr = GitHubPR(owner, repo, pr_number, token)
pr_data = github_pr.get_pr_info()
if pr_data:
# github_pr.save_pr_info(pr_data, "pr_info.json")
# print("PR information saved as pr_info.json")
swe_json = {
"problem_statement": pr_data,
"instance_id": "SWE-agent__test-repo-i1",
"problem_statement_source": "online",
"repo": "https://github.com/icoding1010/my-test-project/",
"repo_type": "github",
"base_commit": os.getenv("BASE_COMMIT"),
"version": os.getenv("VERSION"),
}
save_swe_json(swe_json, "swe_json_data.json")
else:
print("Failed to fetch PR information.")

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions test/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def add(a, b):
return a+b

add(2, 3)
print("Created a folder in branch1. Currently writing in branch1. Will make a pr to see how it reacts.")