Skip to content

Instantly share code, notes, and snippets.

@prashantsengar
Last active January 9, 2022 10:28
Show Gist options
  • Save prashantsengar/d1888b9acbc9727141da00e01afc1c81 to your computer and use it in GitHub Desktop.
Save prashantsengar/d1888b9acbc9727141da00e01afc1c81 to your computer and use it in GitHub Desktop.
Remove spam issues from your GitHub repo
# pip install PyGithub
# This script will edit the title and body of all spam issues to "Spam", add a label "spam" to those issues
# set them as closed and lock the conversation
# Just set your GitHub Personal Access Token (Account settings > Developer settings > Personal Access tokens.
# Create a token with all the permissions for "repo" (probably the first one in the permission list)
import os
from github import Github
access_token = os.environ.get("gh_access_token")
reponame = "username/repo"
# If the spammer created spam issues #100 to #110,
# enter 100 in spam_issue_start and 110 in spam_issue_end
spam_issue_start = # first spam ISSUE number
spam_issue_end = # last spam issue number
g = Github(access_token)
repo = g.get_repo(reponame)
def mark_spam_and_lock():
for i in range(spam_issue_start, spam_issue_end+1):
issue = repo.get_issue(number=i)
issue.set_labels("spam")
issue.edit(title="spam", body="spam", labels=["spam"], state="closed")
issue.lock("spam")
mark_spam_and_lock()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment