Github issue update
Tags: #canny #product
Author: Martin Donadieu

Input

Install package

1
pip install PyGithub
Copied!

Import librairies

1
import requests
2
import json
3
from github import Github
Copied!

Insert your accounts details

1
# For Github
2
gihub_personal_token = "YOUR_GITHUB_TOKEN" # Settings/Developer settings/Personal access tokens
3
github_repo = "optimusprime2021/api-tester" # Github repository name
4
5
# For Canny
6
canny_post_url = "https://canny.io/api/v1/posts/list" # Canny post url
7
canny_apikey = "CANNY_API_KEY" # Canny api key
Copied!

Model

Get Canny posts Dataframe

1
response = requests.get(canny_post_url)
2
data = {"apiKey":canny_apikey,"id":"","limit":"100"}
3
response = requests.post(canny_post_url,data)
4
post_details = response.json()
Copied!

Check connection status

1
if response.status_code == 200:
2
print("Successfully connected to Canny")
3
elif response.status_code == 404:
4
print("Couldn't connect to Canny, Please check the credentials")
5
exit()
Copied!

Generating dataframe

1
import pandas as pd
2
pd.set_option('mode.chained_assignment', None)
3
dd = post_details['posts']
4
df = pd.DataFrame(columns = dd[0].keys())
5
for i in range(len(dd)):
6
df = df.append(dd[i], ignore_index=True)
7
# df
8
9
board = []
10
category = []
11
tags = []
12
for i in range(len(df)):
13
board.append(df['board'][i]['name'])
14
if not df['category'][i]:
15
category.append('Not assigned')
16
else:
17
category.append(df['category'][i]['name'])
18
if not df['tags'][i]:
19
tags.append('Not assigned')
20
else:
21
tags.append(df['tags'][i][0]['name'])
22
23
24
df = df[['title','status','details','url']]
25
df['board'] = board
26
df['category'] = category
27
df['tags'] = tags
28
df = df[(df["tags"] == "Awesome-notebooks")] # tag name
29
df
Copied!
1
## add url to dataframe
Copied!

Existing issue list

1
issues = []
2
g = Github(gihub_personal_token)
3
repo = g.get_repo(github_repo)
4
open_issues = repo.get_issues(state='open')
5
for issue in open_issues:
6
issues.append(issue.title)
Copied!

Output

Push all issues

1
repo = g.get_repo(github_repo)
2
for i in df.index:
3
if df['title'][i] not in issues:
4
repo.create_issue(title=df['title'][i], body=df['details'][i]+"\n canny url: "+df['url'][i])
Copied!

Close all issues

1
# repo = g.get_repo(github_repo)
2
# open_issues = repo.get_issues(state='open')
3
# for issue in open_issues:
4
# issue.edit(state='closed')
Copied!
Last modified 2mo ago
Copy link
Edit on GitHub