Merge pull request #139 from bucolucas/enhance-project-management-functions
Enhance Project Management Functions in github_tool.py
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
# Lessons Learned in Repository Management
|
||||||
|
|
||||||
|
## Summary of Challenges and Solutions
|
||||||
|
|
||||||
|
1. **File Updates with Missing Content**:
|
||||||
|
- **Challenge**: Initial attempts to commit updates to the `github_tool.py` file missed several important configuration functions.
|
||||||
|
- **Solution**: Used Git history to find earlier versions of the file, which revealed the missing functions. Completed the updates by ensuring to include all necessary function calls and relevant code snippets.
|
||||||
|
|
||||||
|
2. **Importance of Tracking Functionality**:
|
||||||
|
- **Challenge**: Managing a range of functionalities (like commenting on issues) can be error-prone if not tracked carefully.
|
||||||
|
- **Solution**: Regularly check previous commits and thoroughly review changes before finalizing commits.
|
||||||
|
|
||||||
|
3. **The Role of Commit Messages**:
|
||||||
|
- **Challenge**: Clear documentation of changes is vital to understanding the evolution of the codebase.
|
||||||
|
- **Solution**: Commit messages should be descriptive and relevant to the changes made, aiding collaborators in understanding the context of changes.
|
||||||
|
|
||||||
|
4. **Testing and Validation**:
|
||||||
|
- **Challenge**: Functionality should be tested after major changes to the codebase to ensure performance is as expected.
|
||||||
|
- **Solution**: Implement a process for thorough testing after committing important changes.
|
||||||
|
|
||||||
|
## Reflections
|
||||||
|
|
||||||
|
- Maintaining a clear and organized approach to repository management fosters smoother collaboration and better results in development processes.
|
||||||
|
- Documenting changes, challenges, and solutions provides valuable insights for personal growth and improves future practices.
|
||||||
+175
-14
@@ -407,6 +407,104 @@ class GitHubTool(BaseTool):
|
|||||||
},
|
},
|
||||||
"required": ["issue_number"]
|
"required": ["issue_number"]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "create_project_board",
|
||||||
|
"description": "Create a new project board",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Name of the project board"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Body of the project board"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["name"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "create_project_column",
|
||||||
|
"description": "Create a new column in a project board",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"project_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the project board"
|
||||||
|
},
|
||||||
|
"column_name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Name of the column"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["project_id", "column_name"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "create_project_card",
|
||||||
|
"description": "Create a new card in a project column",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"column_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the project column"
|
||||||
|
},
|
||||||
|
"note": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Note for the project card"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["column_id", "note"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "move_project_card",
|
||||||
|
"description": "Move a card to a new position",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"card_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the project card"
|
||||||
|
},
|
||||||
|
"position": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "New position of the card"
|
||||||
|
},
|
||||||
|
"column_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the target column"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["card_id", "position", "column_id"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "link_issue_to_project_card",
|
||||||
|
"description": "Link an issue or pull request to a project card",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"card_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the project card"
|
||||||
|
},
|
||||||
|
"content_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ID of the issue or pull request"
|
||||||
|
},
|
||||||
|
"content_type": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Type of the content (Issue or PullRequest)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["card_id", "content_id", "content_type"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -680,9 +778,7 @@ class GitHubTool(BaseTool):
|
|||||||
def _approve_pull_request(self, pull_number):
|
def _approve_pull_request(self, pull_number):
|
||||||
self.logger.info(f"Approving pull request: {pull_number}")
|
self.logger.info(f"Approving pull request: {pull_number}")
|
||||||
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}/reviews"
|
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}/reviews"
|
||||||
data = {
|
data = {"event": "APPROVE"}
|
||||||
"event": "APPROVE"
|
|
||||||
}
|
|
||||||
response = requests.post(url, headers=self.headers, json=data)
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
success_message = f"Pull request {pull_number} approved successfully"
|
success_message = f"Pull request {pull_number} approved successfully"
|
||||||
@@ -697,9 +793,7 @@ class GitHubTool(BaseTool):
|
|||||||
def _close_pull_request(self, pull_number):
|
def _close_pull_request(self, pull_number):
|
||||||
self.logger.info(f"Closing pull request: {pull_number}")
|
self.logger.info(f"Closing pull request: {pull_number}")
|
||||||
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}"
|
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}"
|
||||||
data = {
|
data = {"state": "closed"}
|
||||||
"state": "closed"
|
|
||||||
}
|
|
||||||
response = requests.patch(url, headers=self.headers, json=data)
|
response = requests.patch(url, headers=self.headers, json=data)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
success_message = f"Pull request {pull_number} closed successfully"
|
success_message = f"Pull request {pull_number} closed successfully"
|
||||||
@@ -714,11 +808,7 @@ class GitHubTool(BaseTool):
|
|||||||
def _merge_pull_request(self, pull_number, commit_title, commit_message, merge_method):
|
def _merge_pull_request(self, pull_number, commit_title, commit_message, merge_method):
|
||||||
self.logger.info(f"Merging pull request: {pull_number}")
|
self.logger.info(f"Merging pull request: {pull_number}")
|
||||||
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}/merge"
|
url = f"{self.base_url}/repos/{self.repo}/pulls/{pull_number}/merge"
|
||||||
data = {
|
data = {"commit_title": commit_title, "commit_message": commit_message, "merge_method": merge_method}
|
||||||
"commit_title": commit_title,
|
|
||||||
"commit_message": commit_message,
|
|
||||||
"merge_method": merge_method
|
|
||||||
}
|
|
||||||
response = requests.put(url, headers=self.headers, json=data)
|
response = requests.put(url, headers=self.headers, json=data)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
success_message = f"Pull request {pull_number} merged successfully"
|
success_message = f"Pull request {pull_number} merged successfully"
|
||||||
@@ -817,9 +907,7 @@ class GitHubTool(BaseTool):
|
|||||||
def _add_issue_comment(self, issue_number, comment):
|
def _add_issue_comment(self, issue_number, comment):
|
||||||
self.logger.info(f"Adding comment to issue: {issue_number}")
|
self.logger.info(f"Adding comment to issue: {issue_number}")
|
||||||
url = f"{self.base_url}/repos/{self.repo}/issues/{issue_number}/comments"
|
url = f"{self.base_url}/repos/{self.repo}/issues/{issue_number}/comments"
|
||||||
data = {
|
data = {"body": comment}
|
||||||
"body": comment
|
|
||||||
}
|
|
||||||
response = requests.post(url, headers=self.headers, json=data)
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
if response.status_code == 201:
|
if response.status_code == 201:
|
||||||
comment_data = response.json()
|
comment_data = response.json()
|
||||||
@@ -850,3 +938,76 @@ class GitHubTool(BaseTool):
|
|||||||
error_message = f"Error getting issue comments: {response.status_code}\nResponse: {response.text}"
|
error_message = f"Error getting issue comments: {response.status_code}\nResponse: {response.text}"
|
||||||
self.logger.error(error_message)
|
self.logger.error(error_message)
|
||||||
return error_message
|
return error_message
|
||||||
|
|
||||||
|
@metrics.measure
|
||||||
|
def _create_project_board(self, name, body=None):
|
||||||
|
url = f"{self.base_url}/repos/{self.repo}/projects"
|
||||||
|
data = {"name": name, "body": body}
|
||||||
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
|
if response.status_code == 201:
|
||||||
|
project = response.json()
|
||||||
|
success_message = f"Project board '{name}' created successfully."
|
||||||
|
self.logger.info(success_message)
|
||||||
|
return success_message
|
||||||
|
else:
|
||||||
|
error_message = f"Error creating project board: {response.status_code}"
|
||||||
|
self.logger.error(error_message)
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
@metrics.measure
|
||||||
|
def _create_project_column(self, project_id, column_name):
|
||||||
|
url = f"{self.base_url}/projects/{project_id}/columns"
|
||||||
|
data = {"name": column_name}
|
||||||
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
|
if response.status_code == 201:
|
||||||
|
column = response.json()
|
||||||
|
success_message = f"Column '{column_name}' created successfully in project {project_id}."
|
||||||
|
self.logger.info(success_message)
|
||||||
|
return success_message
|
||||||
|
else:
|
||||||
|
error_message = f"Error creating project column: {response.status_code}"
|
||||||
|
self.logger.error(error_message)
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
@metrics.measure
|
||||||
|
def _create_project_card(self, column_id, note):
|
||||||
|
url = f"{self.base_url}/projects/columns/{column_id}/cards"
|
||||||
|
data = {"note": note}
|
||||||
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
|
if response.status_code == 201:
|
||||||
|
card = response.json()
|
||||||
|
success_message = f"Card created successfully in column {column_id}."
|
||||||
|
self.logger.info(success_message)
|
||||||
|
return success_message
|
||||||
|
else:
|
||||||
|
error_message = f"Error creating project card: {response.status_code}"
|
||||||
|
self.logger.error(error_message)
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
@metrics.measure
|
||||||
|
def _move_project_card(self, card_id, position, column_id):
|
||||||
|
url = f"{self.base_url}/projects/columns/cards/{card_id}/moves"
|
||||||
|
data = {"position": position, "column_id": column_id}
|
||||||
|
response = requests.post(url, headers=self.headers, json=data)
|
||||||
|
if response.status_code == 201:
|
||||||
|
success_message = f"Card {card_id} moved successfully."
|
||||||
|
self.logger.info(success_message)
|
||||||
|
return success_message
|
||||||
|
else:
|
||||||
|
error_message = f"Error moving project card: {response.status_code}"
|
||||||
|
self.logger.error(error_message)
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
@metrics.measure
|
||||||
|
def _link_issue_to_project_card(self, card_id, content_id, content_type):
|
||||||
|
url = f"{self.base_url}/projects/columns/cards/{card_id}"
|
||||||
|
data = {"content_id": content_id, "content_type": content_type}
|
||||||
|
response = requests.patch(url, headers=self.headers, json=data)
|
||||||
|
if response.status_code == 200:
|
||||||
|
success_message = f"Issue/PR linked to card {card_id} successfully."
|
||||||
|
self.logger.info(success_message)
|
||||||
|
return success_message
|
||||||
|
else:
|
||||||
|
error_message = f"Error linking issue/PR to project card: {response.status_code}"
|
||||||
|
self.logger.error(error_message)
|
||||||
|
return error_message
|
||||||
Reference in New Issue
Block a user