Last active
December 6, 2015 19:17
-
-
Save joemidi/4d15074ab351faf1a4d2 to your computer and use it in GitHub Desktop.
Creates a project-directory on a server that is git ready with a pre-installed hook
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
#!/bin/bash | |
echo -n "Enter the project name > " | |
read project_name | |
echo -n "Enter the task ID > " | |
read task_id | |
DIRECTORY=/var/www/html/${project_name} | |
if [ ! -d "$DIRECTORY" ]; then | |
mkdir -p /var/www/html/${project_name}/git && cd $_ && git init --bare | |
touch hooks/post-receive | |
echo -e "#!/bin/bash | |
# Generate your personal access token from your profile settings — apps. | |
# See: https://asana.com/guide/help/api/api | |
personal_access_token=\"\" | |
task_id=\"${task_id}\" | |
print_comment=\"New preview available at: https://example.com/${project_name}\" | |
while read oldrev newrev ref | |
do | |
if [[ \$ref =~ .*/deploy$ ]]; then | |
echo \"Deploy ref received. Deploying branch to preview.\" | |
git --work-tree=/var/www/html/${project_name} --git-dir=/var/www/html/${project_name}/git checkout -f deploy | |
if [[ \"\${task_id}\" ]]; then | |
echo \"Notifying users on Asana.\" | |
curl -H \"Authorization: Bearer \${personal_access_token}\" \\ | |
https://app.asana.com/api/1.0/tasks/\${task_id}/stories \\ | |
-d \"text=\${print_comment}\" > /dev/null 2>&1 | |
fi | |
else | |
echo \"Ref \$ref successfully received. Doing nothing: no work-tree with that branch name found on this server.\" | |
fi | |
done" > hooks/post-receive | |
chmod +x hooks/post-receive | |
else | |
echo "Sorry a directory with that project name already exists." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment