Skip to content

Commit 84297a6

Browse files
authored
Merge pull request #68 from fnic-lemmy/github-issues
Raise GitHub issue when discover_community fails Fixes #66
2 parents 210d0c7 + 861b4bc commit 84297a6

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

bestof.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import requests
1414
import urllib.parse
1515
import datetime
16+
import issues
1617
from urllib.parse import urlparse
1718
from pythorhead import Lemmy
1819
from pythorhead.types import SortType
@@ -99,7 +100,7 @@ def gen_shield(c):
99100
return f'![{serv}](https://img.shields.io/{serv}/{cenc}?style=flat&label=Subs&color=pink)'
100101

101102

102-
def run(user, pw, instance, postcomm, cfg, post_title, images_only, nsfw_b, moduser, modpw, rapidkey):
103+
def run(user, pw, instance, postcomm, cfg, post_title, images_only, nsfw_b, moduser, modpw, rapidkey, ghtoken, ghrepo):
103104
topposts = 0
104105
toppost = []
105106

@@ -137,6 +138,10 @@ def run(user, pw, instance, postcomm, cfg, post_title, images_only, nsfw_b, modu
137138
community_id = lemmy.discover_community(comm)
138139
except Exception as e:
139140
print(f'discover {comm} failed: {e}\n')
141+
try:
142+
issues.raise_issue(ghtoken, ghrepo, f'Remove {comm}', f'discover_community returned:\n\n```\n{e}\n```\n')
143+
except Exception as ghe:
144+
print(f'error raising github issue: {ghe}\n')
140145
continue # skip communities we can't find
141146

142147
if community_id is not None:

deploy.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ region="europe-west1"
44
55
mod_user="fnicmodbot"
66
mod_pw="fnicmodbot-dbzer0:latest"
7-
gist="94127e24dc129210db8dfb819dd8d6b1"
8-
ghtoken="gh-fnic-bot-gist:latest"
7+
ghrepo="fnic-lemmy/bestofbot"
8+
ghtoken="fnic-bot-issues:latest"
99
nsfw="2"
1010

1111
gc_deploy() {
12-
gcloud run jobs deploy bestofbot-$4 --project=$project --region=$region --source . --set-env-vars=BOTUSER="best_of_$1_bot",BOTINSTANCE="lemmy.dbzer0.com",COMMUNITY="$comm",COMMLIST="configs/$4.json",MODUSER="$mod_user",IMAGES_ONLY=$2,NSFW_BEHAVIOUR=$5,GIST=$gist,POSTTITLE="$3" --set-secrets="BOTPW=best_of_$1_bot:latest,MODPW=$mod_pw,GHTOKEN=$ghtoken,TLDRTHIS_API=rapidapi:latest" &
12+
gcloud run jobs deploy bestofbot-$4 --project=$project --region=$region --source . --set-env-vars=BOTUSER="best_of_$1_bot",BOTINSTANCE="lemmy.dbzer0.com",COMMUNITY="$comm",COMMLIST="configs/$4.json",MODUSER="$mod_user",IMAGES_ONLY=$2,NSFW_BEHAVIOUR=$5,GHREPO="$ghrepo",POSTTITLE="$3" --set-secrets="BOTPW=best_of_$1_bot:latest,MODPW=$mod_pw,GHTOKEN=$ghtoken,TLDRTHIS_API=rapidapi:latest" &
1313
}
1414

1515
gc_deploy_quick() {
@@ -41,5 +41,5 @@ gc_deploy "memes" "1" "❗Top Memes (Shows) posts of the month❗" "memes-shows"
4141
gc_deploy "memes" "1" "❗Top Memes (Games) posts of the month❗" "memes-games" "$nsfw"
4242
gc_deploy "memes" "1" "❗Top Memes (Social Media) posts of the month❗" "memes-social" "$nsfw"
4343

44-
gcloud run jobs deploy bestofbot-anime --project=$project --region=$region --source . --set-env-vars=BOTUSER="moebot",BOTINSTANCE="ani.social",COMMUNITY="$comm",COMMLIST="configs/anime.json",IMAGES_ONLY=1,NSFW_BEHAVIOUR=1,GIST=$gist,POSTTITLE="💢❗Top Anime Art posts of the month❗💢" --set-secrets="BOTPW=moebot:latest,GHTOKEN=$ghtoken" &
44+
gcloud run jobs deploy bestofbot-anime --project=$project --region=$region --source . --set-env-vars=BOTUSER="moebot",BOTINSTANCE="ani.social",COMMUNITY="$comm",COMMLIST="configs/anime.json",IMAGES_ONLY=1,NSFW_BEHAVIOUR=1,GHREPO="$ghrepo",POSTTITLE="💢❗Top Anime Art posts of the month❗💢" --set-secrets="BOTPW=moebot:latest,GHTOKEN=$ghtoken" &
4545
wait

issues.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/python3
2+
from github import Github
3+
from github import Auth
4+
from github import Repository
5+
6+
def raise_issue(ghtoken, ghrepo, title, desc):
7+
8+
auth = Auth.Token(ghtoken)
9+
g = Github(auth=auth)
10+
repo = g.get_repo(ghrepo)
11+
my_issues = repo.get_issues(state = "open", creator = "fnic-bot")
12+
for issue in my_issues:
13+
print(issue)
14+
if issue.title == title:
15+
print('already raised')
16+
issue.create_comment(f'This has failed again.\n\n{desc}')
17+
return
18+
19+
i = repo.create_issue(title = title, body = desc, labels = [repo.get_label(name = "community")])

main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@
1616
NSFW = os.getenv("NSFW_BEHAVIOUR", 0)
1717
MODUSER = os.getenv("MODUSER",0)
1818
MODPW = os.getenv("MODPW", 0)
19-
GIST = os.getenv("GIST", 0)
19+
GHREPO = os.getenv("GHREPO", 0)
2020
GHTOKEN = os.getenv("GHTOKEN", 0)
2121
TLDRTHIS_APIKEY = os.getenv("TLDRTHIS_API", 0)
2222

23-
def main(user, pw, inst, comm, cfg, title, imgs, nsfw, moduser, modpw, gist, ghtoken, tldr_api):
23+
def main(user, pw, inst, comm, cfg, title, imgs, nsfw, moduser, modpw, ghrepo, ghtoken, tldr_api):
2424

2525
io = False
2626

2727
if imgs == 1:
2828
io = True
2929

30-
contents = bestof.run(user, pw, inst, comm, cfg, title, io, nsfw, moduser, modpw, tldr_api)
30+
contents = bestof.run(user, pw, inst, comm, cfg, title, io, nsfw, moduser, modpw, tldr_api, ghtoken, ghrepo)
3131

3232
return "bestofbot"
3333

3434
# Start script
3535
if __name__ == "__main__":
3636
try:
3737
main(BOTUSER, BOTPW, BOTINSTANCE, POSTCOMMUNITY, COMMUNITIES, TITLE,
38-
int(IMAGESONLY), int(NSFW), MODUSER, MODPW, GIST, GHTOKEN, TLDRTHIS_APIKEY)
38+
int(IMAGESONLY), int(NSFW), MODUSER, MODPW, GHREPO, GHTOKEN, TLDRTHIS_APIKEY)
3939
except Exception as err:
4040
message = (
4141
f"Task #{TASK_INDEX}, " + f"Attempt #{TASK_ATTEMPT} failed: {str(err)}"

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pythorhead==0.25.0
2-
PyGithub==2.3.0
2+
PyGithub==2.6.0
33
requests
44
smmrpy
55
aiohttp

0 commit comments

Comments
 (0)