-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validates problem. Checks for missing files. Prompts to confirm submi… #1
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Validates problem. Checks for missing files. Prompts to confirm submi…
…ssion.
- Loading branch information
commit c1a7d18215167b4d1bf7ed4f766db05cd56e05e3
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,44 @@ for cmd in curl expect jq sed; do | |
fi | ||
done | ||
|
||
# TODO: check if problem exists by querying for .gitignore | ||
# ensure problem exists | ||
EXCLUDE=$(mktemp) | ||
if [[ $? -ne 0 ]]; then | ||
echo "Could not create a temporary file." | ||
exit 1 | ||
fi | ||
curl --fail -o "$EXCLUDE" --silent "https://raw.githubusercontent.com/submit50/submit50/$problem/exclude" | ||
if [[ $? -ne 0 ]]; then | ||
echo "Invalid problem. Did you mean to submit something else?" | ||
exit 1 | ||
fi | ||
|
||
# check for missing files | ||
declare -a files | ||
while read line; do | ||
if [[ "$line" =~ ^# ]]; then | ||
file=$(sed 's/^[ \t]*//;s/[ \t]*$//' <<< "${line#?}") | ||
if [[ ! -e "$file" ]]; then | ||
files+=($file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May as well put |
||
fi | ||
unset file | ||
fi | ||
done < "$EXCLUDE" | ||
unset line | ||
if [[ ${#files[@]} -ne 0 ]]; then | ||
echo "You seem to be missing these files:" | ||
printf " %s\n" "${files[@]}" | ||
read -p "Proceed anyway? " -r read | ||
shopt -s nocasematch | ||
if [[ ! "$read" =~ ^\s*(yes|y)\s*$ ]]; then | ||
echo -e -n "\033[31m" | ||
echo "Submission cancelled." | ||
echo -e -n "\033[39m" | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
shopt -u nocasematch | ||
fi | ||
|
||
# ask for GitHub username | ||
while read -p "GitHub username: " -r username | ||
|
@@ -73,17 +110,26 @@ if [[ $? -ne 0 ]]; then | |
if [[ "$username" =~ .*"@".* ]]; then | ||
echo "Log in with your GitHub username, not email address!" | ||
else | ||
echo "Incorrect GitHub username and/or password! Visit https://github.com/password_reset if forgotten." | ||
echo "Incorrect GitHub username and/or password!" | ||
echo "Visit https://github.com/password_reset if forgotten." | ||
fi | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
datetime=$(sed -nr "s/^Date: (.*)/\1/p" <<< "$headers") | ||
# TODO: ensure Date: exists | ||
if [[ -z "$datetime" ]]; then | ||
echo "Can't figure out what time it is!" | ||
echo "Let [email protected] know!" | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
|
||
# GET https://api.github.com/user | ||
user=$(curl --config - --fail --silent "https://api.github.com/user" <<< "user = $username:$password" 2>&1) | ||
if [[ $? -ne 0 ]]; then | ||
echo "Sorry, something's wrong! Let [email protected] know!" | ||
echo "Sorry, something's wrong!" | ||
echo "Let [email protected] know!" | ||
rm -f "$EXCLUDE" | ||
exit | ||
fi | ||
email=$(jq '.email // empty' <<< "$user") | ||
|
@@ -93,14 +139,16 @@ name=$(jq '.name // empty' <<< "$user") | |
curl --config - --fail --head --silent "https://api.github.com/repos/submit50/$username" <<< "user = $username:$password" > /dev/null 2>&1 | ||
if [[ $? -ne 0 ]]; then | ||
echo "Looks like we haven't enabled submit50 for your account yet!" | ||
echo "Email [email protected] and let us know your GitHub username!" | ||
echo "Let [email protected] know your GitHub username!" | ||
rm -f "$EXCLUDE" | ||
exit | ||
fi | ||
|
||
# path to the repository | ||
GIT_DIR=$(mktemp -d) | ||
if [[ $? -ne 0 ]]; then | ||
echo "Could not create a temporary directory." | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
export GIT_DIR | ||
|
@@ -121,12 +169,11 @@ expect <<- EOF | |
EOF | ||
if [[ $? -ne 0 ]]; then | ||
echo "Could not clone https://[email protected]/submit50/$username" | ||
rm -rf "$GIT_DIR" | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
|
||
# TODO: confirm files to submit | ||
#tree=$(git ls-tree -r "$problem" --name-only | jq --raw-input --slurp @json) | ||
|
||
# set options | ||
# https://help.github.com/articles/keeping-your-email-address-private/ | ||
git config user.email "${email:[email protected]}" | ||
|
@@ -135,12 +182,33 @@ git config user.name "${name:-$username}" | |
# updates HEAD to point at $problem | ||
git symbolic-ref HEAD "refs/heads/$problem" | ||
|
||
# patterns of file names to exclude | ||
git config core.excludesFile "$EXCLUDE" | ||
git config core.ignorecase true | ||
|
||
# adds, modifies, and removes index entries to match the working tree | ||
echo -e -n "\033[33m" | ||
echo "git add --all" | ||
echo -e -n "\033[39m" | ||
git add --all | ||
|
||
# confirm submission | ||
echo "Files that will be submitted:" | ||
git ls-files | sed -e 's/^/ /' | ||
echo "Files that won't be submitted:" | ||
git ls-files --other | sed -e 's/^/ /' | ||
read -p "Submit? " -r read | ||
shopt -s nocasematch | ||
if [[ ! "$read" =~ ^\s*(yes|y)\s*$ ]]; then | ||
echo -e -n "\033[31m" | ||
echo "Submission cancelled." | ||
echo -e -n "\033[39m" | ||
rm -rf "$GIT_DIR" | ||
rm -f "$EXCLUDE" | ||
exit 1 | ||
fi | ||
shopt -u nocasematch | ||
|
||
# stores the current contents of the index in a new commit | ||
echo -e -n "\033[33m" | ||
echo "git commit" | ||
|
@@ -196,8 +264,9 @@ expect <<- EOF | |
} | ||
EOF | ||
|
||
# remove repository | ||
# remove temporaries | ||
rm -rf "$GIT_DIR" | ||
rm -f "$EXCLUDE" | ||
|
||
# kthxbai | ||
echo -e -n "\033[32m" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before exiting at line 39, delete
$EXCLUDE
.