forked from longhorn/bot
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create backport issue in github project instead of zenhub
Signed-off-by: Jack Yu <[email protected]>
- Loading branch information
Showing
8 changed files
with
127 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import requests | ||
from harvester_github_bot.github_graphql.ql_queries import GET_ISSUE_QUERY, GET_ORGANIZATION_PROJECT_QUERY, GET_USER_PROJECT_QUERY | ||
from harvester_github_bot.github_graphql.ql_mutation import ADD_ISSUE_TO_PROJECT_MUTATION | ||
|
||
class GitHubProjectManager: | ||
def __init__(self, organization, repository, project_number, headers): | ||
self.organization = organization | ||
self.repository = repository | ||
self.headers = headers | ||
self.url = "https://api.github.com/graphql" | ||
self.__project = self.__get_orgnization_project(project_number) | ||
# self.__project = self.__get_user_project(project_number) # used in testing | ||
|
||
def get_issue(self, issue_number): | ||
variables = { | ||
'repo_owner': self.organization, | ||
'repo_name': self.repository, | ||
'issue_number': issue_number | ||
} | ||
response = requests.post(self.url, headers=self.headers, json={'query': GET_ISSUE_QUERY, 'variables': variables}) | ||
if response.status_code == 200: | ||
return response.json()['data']['repository']['issue'] | ||
else: | ||
raise Exception(f"Query failed to run by returning code of {response.status_code}. {response.json()}") | ||
|
||
def add_issue_to_project(self, issue_id): | ||
variables = { | ||
'project_id': self.__project["id"], | ||
'content_id': issue_id | ||
} | ||
response = requests.post(self.url, headers=self.headers, json={'query': ADD_ISSUE_TO_PROJECT_MUTATION, 'variables': variables}) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
raise Exception(f"Mutation failed to run by returning code of {response.status_code}. {response.json()}") | ||
|
||
def __get_orgnization_project(self, project_number): | ||
variables = { | ||
'organization': self.organization, | ||
'project_number': project_number | ||
} | ||
response = requests.post(self.url, headers=self.headers, json={'query': GET_ORGANIZATION_PROJECT_QUERY, 'variables': variables}) | ||
if response.status_code == 200: | ||
return response.json()['data']['organization']['projectV2'] | ||
else: | ||
raise Exception(f"Query failed to run by returning code of {response.status_code}. {response.json()}") | ||
|
||
|
||
def __get_user_project(self, project_number): | ||
variables = { | ||
'organization': self.organization, | ||
'project_number': project_number | ||
} | ||
response = requests.post(self.url, headers=self.headers, json={'query': GET_USER_PROJECT_QUERY, 'variables': variables}) | ||
if response.status_code == 200: | ||
return response.json()['data']['user']['projectV2'] | ||
else: | ||
raise Exception(f"Query failed to run by returning code of {response.status_code}. {response.json()}") |
9 changes: 9 additions & 0 deletions
9
github-bot/harvester_github_bot/github_graphql/ql_mutation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ADD_ISSUE_TO_PROJECT_MUTATION = """ | ||
mutation($project_id: ID!, $content_id: ID!) { | ||
addProjectV2ItemById(input: {projectId: $project_id, contentId: $content_id}) { | ||
item { | ||
id | ||
} | ||
} | ||
} | ||
""" |
38 changes: 38 additions & 0 deletions
38
github-bot/harvester_github_bot/github_graphql/ql_queries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
GET_ISSUE_QUERY = """ | ||
query($repo_owner: String!, $repo_name: String!, $issue_number: Int!) { | ||
repository(owner: $repo_owner, name: $repo_name) { | ||
issue(number: $issue_number) { | ||
id | ||
number | ||
title | ||
url | ||
} | ||
} | ||
} | ||
""" | ||
|
||
|
||
GET_ORGANIZATION_PROJECT_QUERY = """ | ||
query($organization: String!, $project_number: Int!) { | ||
organization(login: $organization) { | ||
projectV2(number: $project_number) { | ||
id | ||
title | ||
number | ||
} | ||
} | ||
} | ||
""" | ||
|
||
# This is used to test | ||
GET_USER_PROJECT_QUERY = """ | ||
query($organization: String!, $project_number: Int!) { | ||
user(login: $organization) { | ||
projectV2(number: $project_number) { | ||
id | ||
title | ||
number | ||
} | ||
} | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters