1#!/usr/bin/env bash
2
3##############################################################################
4##
5##  GitHub Upload/Sync script for Android Samples
6##
7##############################################################################
8
9##replace with auth token for google-automerger GitHub account
10TOKEN=herpderp
11
12##iterate through samples
13
14cd ./prebuilts/gradle
15for i in $(ls);
16
17##for testing
18#foo="ActionBarCompat-Basic"
19#foo="ActionBarCompat-Basic ActionBarCompat-ListPopupMenu FooBar"
20#foo="ActionBarCompat-Basic Notifications"
21#for i in $foo;
22
23do
24echo "
25$i"
26
27URL=https://github.com/googlesamples/android-$i
28
29result=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$URL")
30#echo "$result $URL"
31
32##checking to see if the repo already exists
33if [ "$result" != "404" ]; then
34   echo "$i already exists as a repo"
35 else
36   echo "A repo for $i does not exist yet"
37
38repoName="googlesamples/android-$i"
39
40#echo "
41#URL Repo Name:
42#"$repoName
43
44
45CREATE="curl -H 'Authorization: token '$TOKEN \
46     -d '{\"name\":\"android-'$i'\", \"team_id\":889859}' \
47     https://api.github.com/orgs/googlesamples/repos"
48
49#echo "
50#Create Script:
51#"$CREATE
52
53eval $CREATE
54
55#add secondary team permissions (robots)
56ADDTEAM="curl -X PUT \
57-H 'Authorization: token '$TOKEN \
58-H 'Content-Length: 0' \
59https://api.github.com/teams/889856/repos/$repoName"
60
61#echo "
62#Add Team Robots:
63#"$ADDTEAM
64
65eval $ADDTEAM
66
67
68URL="https://$TOKEN@github.com/$repoName"
69#echo "
70#Authenticated URL:
71#"$URL
72
73   cd $i
74   git init
75    #overrides .gitconfig just for this project - does not alter your global settings.
76   git config user.name "google-automerger"
77   git config user.email automerger@google.com
78   git add .
79   git commit -m "Initial Commit"
80   git remote add origin $URL
81   git push origin master
82   cd ..
83 fi
84done
85
86