Skip to content

Commit

Permalink
Merge pull request #112 from sopel-irc/gh-repo-improvements
Browse files Browse the repository at this point in the history
github: fix/improve `.gh-repo` command
  • Loading branch information
dgw authored Nov 12, 2022
2 parents d968c82 + 144c7d2 commit 92d728e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sopel_modules/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,29 @@ def issue_info(bot, trigger, match=None):


@commands('gh-repo')
@example('.gh-repo !clear')
@example('.gh-repo sopel-irc/sopel-github')
@require_chanmsg('[GitHub] You can only link a repository to a channel.')
def manage_channel_repo(bot, trigger):
"""
Set the repository to use for looking up standalone issue/PR references.
Use the special value ``!clear`` to clear the linked repository.
"""
allowed = bot.channels[trigger.sender].privileges.get(trigger.nick, 0) >= OP
if not allowed and not trigger.admin:
return bot.say('You must be a channel operator to use this command!')

if not trigger.group(2):
return bot.say(bot.db.get_channel_value('github_issue_repo', trigger.sender))
msg = 'No repo linked to this channel.'
current = bot.db.get_channel_value('github_issue_repo', trigger.sender)
if current:
msg = 'Issue numbers in %s will fetch data for %s.' % (trigger.sender, current)
return bot.say(msg)

if trigger.group(3).lower() == '!clear':
bot.db.delete_channel_value('github_issue_repo', trigger.sender)
return bot.say('Cleared linked repo for %s.' % trigger.sender)

bot.db.set_channel_value('github_issue_repo', trigger.sender, trigger.group(3))
bot.reply('Set linked repo for %s to %s.' % (trigger.sender, trigger.group(3)))
Expand Down

0 comments on commit 92d728e

Please sign in to comment.