Skip to content

Commit 7abc7d6

Browse files
committed
formatting: remove shorten_url()
It hasn't been doing anything useful for a while anyway, since GitHub killed off their git.io shortening service. Now that we definitely expect the full link, the `.gh-hook` command will output the authorization URL on its own line, with `max_messages` set to allow Sopel to split it across multiple messages if needed. Truncation would be very bad in that case.
1 parent bb66e62 commit 7abc7d6

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

sopel_modules/github/formatting.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import re
2121
import textwrap
2222

23-
import requests
24-
2523
from sopel.formatting import color
2624
from sopel import tools
2725

@@ -568,41 +566,32 @@ def fmt_release_message(payload=None):
568566
' (prerelease)' if payload['release']['prerelease'] else '')
569567

570568

571-
def shorten_url(url):
572-
try:
573-
res = requests.post('https://git.io', {'url': url})
574-
return res.headers['location']
575-
except:
576-
LOGGER.exception('Shortening link failed; using long URL.')
577-
return url
578-
579-
580569
def get_formatted_response(payload, row):
581570
global current_row, current_payload
582571
current_payload = payload
583572
current_row = row
584573

585574
messages = []
586575
if payload['event'] == 'push':
587-
messages.append(fmt_push_summary_message() + " " + fmt_url(shorten_url(get_push_summary_url())))
576+
messages.append(fmt_push_summary_message() + " " + fmt_url(get_push_summary_url()))
588577
for commit in get_distinct_commits():
589578
messages.append(fmt_commit_message(commit))
590579
elif payload['event'] == 'commit_comment':
591-
messages.append(fmt_commit_comment_summary() + " " + fmt_url(shorten_url(payload['comment']['html_url'])))
580+
messages.append(fmt_commit_comment_summary() + " " + fmt_url(payload['comment']['html_url']))
592581
elif payload['event'] == 'pull_request':
593582
if re.match('((re)?open|clos)ed', payload['action']) or payload['action'] in ['ready_for_review', 'converted_to_draft']:
594-
messages.append(fmt_pull_request_summary_message() + " " + fmt_url(shorten_url(payload['pull_request']['html_url'])))
583+
messages.append(fmt_pull_request_summary_message() + " " + fmt_url(payload['pull_request']['html_url']))
595584
elif payload['action'] == 'edited':
596585
if 'changes' in payload:
597586
if 'title' in payload['changes']:
598-
messages.append(fmt_pull_request_title_edit() + " " + fmt_url(shorten_url(payload['pull_request']['html_url'])))
587+
messages.append(fmt_pull_request_title_edit() + " " + fmt_url(payload['pull_request']['html_url']))
599588
elif re.match('(assigned|unassigned)', payload['action']):
600-
messages.append(fmt_issue_assignee_message() + " " + fmt_url(shorten_url(payload['pull_request']['html_url'])))
589+
messages.append(fmt_issue_assignee_message() + " " + fmt_url(payload['pull_request']['html_url']))
601590
elif re.match('(labeled|unlabeled)', payload['action']):
602591
if payload.get('label', None):
603592
# If a label is deleted, for example, we'll get a webhook payload with no details about the removed label.
604593
# We skip those; there's no reason to emit action messages to IRC with "unknown label" placeholders.
605-
messages.append(fmt_issue_label_message() + " " + fmt_url(shorten_url(payload['pull_request']['html_url'])))
594+
messages.append(fmt_issue_label_message() + " " + fmt_url(payload['pull_request']['html_url']))
606595
elif payload['event'] == 'pull_request_review':
607596
if payload['action'] == 'submitted' and payload['review']['state'] in ['approved', 'changes_requested', 'commented']:
608597
if payload['review']['state'] == 'commented' and payload['review']['body'] == None:
@@ -611,44 +600,44 @@ def get_formatted_response(payload, row):
611600
# Either way, an empty review must be accompanied by comments, which will get handled when their hook(s) fire(s).
612601
pass
613602
else:
614-
messages.append(fmt_pull_request_review_summary_message() + " " + fmt_url(shorten_url(payload['review']['html_url'])))
603+
messages.append(fmt_pull_request_review_summary_message() + " " + fmt_url(payload['review']['html_url']))
615604
elif payload['action'] == 'dismissed':
616-
messages.append(fmt_pull_request_review_dismissal_message() + " " + fmt_url(shorten_url(payload['review']['html_url'])))
605+
messages.append(fmt_pull_request_review_dismissal_message() + " " + fmt_url(payload['review']['html_url']))
617606
elif payload['event'] == 'pull_request_review_comment' and payload['action'] == 'created':
618-
messages.append(fmt_pull_request_review_comment_summary_message() + " " + fmt_url(shorten_url(payload['comment']['html_url'])))
607+
messages.append(fmt_pull_request_review_comment_summary_message() + " " + fmt_url(payload['comment']['html_url']))
619608
elif payload['event'] == 'issues':
620609
if re.match('((re)?open|clos)ed', payload['action']):
621610
if 'changes' in payload and all(k in payload['changes'] for k in ['old_repository', 'old_issue']):
622-
messages.append(fmt_issue_incoming_transfer_message() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
611+
messages.append(fmt_issue_incoming_transfer_message() + " " + fmt_url(payload['issue']['html_url']))
623612
else:
624-
messages.append(fmt_issue_summary_message() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
613+
messages.append(fmt_issue_summary_message() + " " + fmt_url(payload['issue']['html_url']))
625614
elif re.match('(assigned|unassigned)', payload['action']):
626-
messages.append(fmt_issue_assignee_message() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
615+
messages.append(fmt_issue_assignee_message() + " " + fmt_url(payload['issue']['html_url']))
627616
elif re.match('(labeled|unlabeled)', payload['action']):
628617
if payload.get('label', None):
629618
# If a label is deleted, for example, we'll get a webhook payload with no details about the removed label.
630619
# We skip those; there's no reason to emit action messages to IRC with "unknown label" placeholders.
631-
messages.append(fmt_issue_label_message() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
620+
messages.append(fmt_issue_label_message() + " " + fmt_url(payload['issue']['html_url']))
632621
elif re.match('(milestoned|demilestoned)', payload['action']):
633-
messages.append(fmt_issue_milestone_message() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
622+
messages.append(fmt_issue_milestone_message() + " " + fmt_url(payload['issue']['html_url']))
634623
elif payload['action'] == 'edited':
635624
if 'changes' in payload:
636625
if 'title' in payload['changes']:
637-
messages.append(fmt_issue_title_edit() + " " + fmt_url(shorten_url(payload['issue']['html_url'])))
626+
messages.append(fmt_issue_title_edit() + " " + fmt_url(payload['issue']['html_url']))
638627
elif payload['action'] == 'transferred':
639-
messages.append(fmt_issue_outgoing_transfer_message() + " " + fmt_url(shorten_url(payload['changes']['new_issue']['html_url'])))
628+
messages.append(fmt_issue_outgoing_transfer_message() + " " + fmt_url(payload['changes']['new_issue']['html_url']))
640629
elif payload['event'] == 'issue_comment' and payload['action'] == 'created':
641-
messages.append(fmt_issue_comment_summary_message() + " " + fmt_url(shorten_url(payload['comment']['html_url'])))
630+
messages.append(fmt_issue_comment_summary_message() + " " + fmt_url(payload['comment']['html_url']))
642631
elif payload['event'] == 'gollum':
643632
url = payload['pages'][0]['html_url'] if len(payload['pages']) else payload['repository']['url'] + '/wiki'
644-
messages.append(fmt_gollum_summary_message() + " " + fmt_url(shorten_url(url)))
633+
messages.append(fmt_gollum_summary_message() + " " + fmt_url(url))
645634
elif payload['event'] == 'watch':
646635
messages.append(fmt_watch_message())
647636
elif payload['event'] == 'status':
648637
messages.append(fmt_status_message())
649638
elif payload['event'] == 'release':
650639
if payload['action'] == 'published':
651640
# Currently the only possible action, but other events might eventually fire webhooks too
652-
messages.append(fmt_release_message() + " " + fmt_url(shorten_url(payload['release']['html_url'])))
641+
messages.append(fmt_release_message() + " " + fmt_url(payload['release']['html_url']))
653642

654643
return messages

sopel_modules/github/github.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sopel.config.types import StaticSection, ValidatedAttribute
2020

2121
from . import formatting
22-
from .formatting import shorten_url, emojize
22+
from .formatting import emojize
2323
from .webhook import setup_webhook, shutdown_webhook
2424

2525
import operator
@@ -224,9 +224,8 @@ def issue_info(bot, trigger, match=None):
224224

225225
# append link, if not triggered by a link
226226
if not match:
227-
link = shorten_url(data['html_url'])
228227
response.append(bold(' | '))
229-
response.append(link)
228+
response.append(data['html_url'])
230229

231230
bot.say(''.join(response))
232231

@@ -519,13 +518,15 @@ def configure_repo_messages(bot, trigger):
519518
if not result:
520519
c.execute('''INSERT INTO gh_hooks (channel, repo_name, enabled) VALUES (?, ?, ?)''', (channel, repo_name, enabled))
521520
bot.say("Successfully enabled listening for {repo}'s events in {chan}.".format(chan=channel, repo=repo_name))
522-
bot.say('Great! Please allow me to create my webhook by authorizing via this link: ' + shorten_url(auth_url))
521+
bot.say('Great! Please allow me to create my webhook by authorizing via this link:')
522+
bot.say(auth_url, max_messages=10)
523523
bot.say('Once that webhook is successfully created, I\'ll post a message in here. Give me about a minute or so to set it up after you authorize. You can configure the colors that I use to display webhooks with {}gh-hook-color'.format(bot.config.core.help_prefix))
524524
else:
525525
c.execute('''UPDATE gh_hooks SET enabled = ? WHERE channel = ? AND repo_name = ?''', (enabled, channel, repo_name))
526526
bot.say("Successfully {state} the subscription to {repo}'s events".format(state='enabled' if enabled else 'disabled', repo=repo_name))
527527
if enabled:
528-
bot.say('Great! Please allow me to create my webhook by authorizing via this link: ' + shorten_url(auth_url))
528+
bot.say('Great! Please allow me to create my webhook by authorizing via this link:')
529+
bot.say(auth_url, max_messages=10)
529530
bot.say('Once that webhook is successfully created, I\'ll post a message in here. Give me about a minute or so to set it up after you authorize. You can configure the colors that I use to display webhooks with {}gh-hook-color'.format(bot.config.core.help_prefix))
530531
conn.commit()
531532
conn.close()

0 commit comments

Comments
 (0)