Skip to content

Commit

Permalink
Fix blacklist PRs and add git credidentials check
Browse files Browse the repository at this point in the history
  • Loading branch information
angussidney committed Jan 18, 2017
1 parent 5f495ba commit 2351bf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions chatcommands.py
Expand Up @@ -265,7 +265,7 @@ def command_blacklist_help(*args, **kwargs):
return Response(command_status=True, message="The !!/blacklist command has been deprecated. "
"Please use !!/blacklist-website, !!/blacklist-username "
"or !!/blacklist-keyword. Remember to escape dots "
"in URLs using \\. and spaces in keywords with \s.")
"in URLs using \\.")


# noinspection PyIncorrectDocstring,PyUnusedLocal
Expand Down Expand Up @@ -1450,7 +1450,7 @@ def subcommand_autoflagged(msg_content, post_url, *args, **kwargs):
"!!/errorlogs": command_errorlogs,
"!!/gitstatus": command_gitstatus,
"!!/help": command_help,
"!!/hats": command_hats,
# "!!/hats": command_hats, (uncomment when Winterbash begins)
"!!/info": command_help,
"!!/isblu": command_check_blacklist,
"!!/iswlu": command_check_whitelist,
Expand Down
26 changes: 14 additions & 12 deletions gitmanager.py
Expand Up @@ -16,6 +16,13 @@ def add_to_blacklist(**kwargs):
chat_profile_link = kwargs.get("chat_profile_link", "http://chat.stackexchange.com/users")
code_permissions = kwargs.get("code_permissions", False)

# Make sure git credentials are set up
if git.config("--global", "--get", "user.name") == "":
return (False, "Tell someone to run `git config --global user.name \"SmokeDetector\"`")

if git.config("--global", "--get", "user.name") == "":
return (False, "Tell someone to run `git config --global user.email \"smokey@erwaysoftware.com\"`")

if blacklist == "":
# If we broke the code, and this isn't assigned, error out before doing anything, but do
# so gracefully with a nice error message.
Expand Down Expand Up @@ -55,9 +62,9 @@ def add_to_blacklist(**kwargs):

# Check that blacklisted_websites.txt isn't modified locally. That could get ugly fast
if blacklist_file_name in git.status(): # Also ugly
return (False, "{0} modified locally. This is probably bad.".format(blacklist_file_name))
return (False, "{0} is modified locally. This is probably bad.".format(blacklist_file_name))

# Add items to file
# Add item to file
with open(blacklist_file_name, "a+") as blacklist_file:
last_character = blacklist_file.read()[-1:]
if last_character != "\n":
Expand Down Expand Up @@ -85,17 +92,12 @@ def add_to_blacklist(**kwargs):
if GlobalVars.github_username is None or GlobalVars.github_password is None:
return (False, "Tell someone to set a GH password")

list_of_items = ""

for item in range(len(item_to_blacklist)):
list_of_items += "\n - {0} - [MS search](https://metasmoke.erwaysoftware.com/search?" \
"utf8=%E2%9C%93{1}{2})".format(item_to_blacklist[item], ms_search_option,
item_to_blacklist[item].replace(" ", "+"))

payload = {"title": "{0}: Blacklist {1}".format(username, item_to_blacklist),
"body": "[{0}]({1}) requests the blacklist of the following {2}(s): \n{3}\n"
"<!-- METASMOKE-BLACKLIST {4} -->".format(username, chat_profile_link, blacklist,
list_of_items, "|".join(item_to_blacklist)),
"body": "[{0}]({1}) requests the blacklist of the {2} {3}. See the Metasmoke search [here]"
"(https://metasmoke.erwaysoftware.com/search?utf8=%E2%9C%93{4}{5})\n"
"<!-- METASMOKE-BLACKLIST {6} -->".format(username, chat_profile_link, blacklist,
item_to_blacklist, ms_search_option,
item_to_blacklist.replace(" ", "+")),
"head": branch,
"base": "master"}
response = requests.post("https://api.github.com/repos/Charcoal-SE/SmokeDetector/pulls",
Expand Down

0 comments on commit 2351bf8

Please sign in to comment.