Skip to content

Commit

Permalink
Delete scrum integration
Browse files Browse the repository at this point in the history
  • Loading branch information
annndruha committed Mar 16, 2023
1 parent 35e7500 commit 26f3fe0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
32 changes: 1 addition & 31 deletions src/github_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Marakulin Andrey https://github.com/Annndruha
# 2023
import logging

import requests


class Github:
def __init__(self, organization_nickname, token):
self.organization_nickname = organization_nickname
self.issue_url = 'https://api.github.com/repos/' + organization_nickname + '/{}/issues'
self.graphql_url = 'https://api.github.com/graphql'
self.org_repos_url = f'https://api.github.com/orgs/{organization_nickname}/repos'
Expand All @@ -21,7 +19,7 @@ def __init__(self, organization_nickname, token):
}

def open_issue(self, repo, title, comment):
payload = {'title': title, 'body': comment, 'projects': f'{self.organization_nickname}/7'}
payload = {'title': title, 'body': comment}
r = requests.post(self.issue_url.format(repo), headers=self.headers, json=payload)
if 'Issues are disabled for this repo' in r.text:
raise GithubIssueDisabledError
Expand Down Expand Up @@ -64,34 +62,6 @@ def set_assignee(self, repo, number_str, member_login, comment):
r = requests.patch(url, headers=self.headers, json=payload)
return r

def add_to_scrum(self, node_id):
try:
PROJECT_ID = 'PVT_kwDOBaPiZM4AFiz-'
add_item_to_scrum = {'query': 'mutation{ addProjectV2ItemById(input: {projectId: "%s" contentId: "%s"}) { '
'item { id } } }' % (PROJECT_ID, node_id)}
r = requests.post(url=self.graphql_url, json=add_item_to_scrum, headers=self.headers)

if 'errors' not in r.json():
logging.info(f'Node {node_id} successfully added to scrum Твой ФФ!')
else:
logging.warning(f'Node {node_id} not added to scrum. Reason: {r.json()["errors"]}')

FIELD_ID = 'PVTSSF_lADOBaPiZM4AFiz-zgDMeOc'
BACKLOG_OPTION_ID = '4a4a1bb5'
set_item_status_to_scrum = {'query': 'mutation {updateProjectV2ItemFieldValue(input: '
'{projectId: "%s", itemId: "%s", fieldId: '
'"%s",value: {singleSelectOptionId: "%s"}}) '
'{projectV2Item{id}}}' % (PROJECT_ID, node_id,
FIELD_ID, BACKLOG_OPTION_ID)}

r = requests.post(url=self.graphql_url, json=set_item_status_to_scrum, headers=self.headers)
if 'errors' not in r.json():
logging.info(f'Node {node_id} successfully set backlog status.')
else:
logging.warning(f'Node {node_id} not set status. Reason: {r.json()["errors"]}')
except Exception as err:
logging.error(f'Scrum adding FAILED: {err.args}')


class GithubIssueDisabledError(Exception):
pass
2 changes: 0 additions & 2 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ async def __create_issue(update: Update, context: ContextTypes.DEFAULT_TYPE):
logging.info(f'[{update.callback_query.from_user.id} {update.callback_query.from_user.full_name}]'
f'[{update.callback_query.message.id}] Succeeded open Issue: {response["html_url"]}')

github.add_to_scrum(response['node_id'])

else:
await context.bot.answer_callback_query(update.callback_query.id, f'Response code: {r.status_code}')
text = __join_to_message_text(title, 'No repo', assigned, comment, '⚠️')
Expand Down

0 comments on commit 26f3fe0

Please sign in to comment.