kokoro: add synth config (#489)
diff --git a/internal/kokoro/synth/sendpr/sendpr.go b/internal/kokoro/synth/sendpr/sendpr.go
new file mode 100644
index 0000000..6e4f8a5
--- /dev/null
+++ b/internal/kokoro/synth/sendpr/sendpr.go
@@ -0,0 +1,47 @@
+// Copyright 2020 Google Inc. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "bytes"
+ "encoding/json"
+ "flag"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+)
+
+func main() {
+ title := flag.String("title", "", "title for PR")
+ flag.Parse()
+
+ payload := map[string]interface{}{
+ "title": *title,
+ "body": "", // TODO
+ "head": "synth-update",
+ "base": "master",
+ }
+ body, err := json.Marshal(payload)
+ if err != nil {
+ log.Fatal(err)
+ }
+ req := http.NewRequest("POST", "https://api.github.com/repos/googleapis/google-api-go-client/pulls", bytes.NewReader(body))
+ req.Headers.Set("Accept", "application/vnd.github.v3+json")
+ req.Headers.Set("Authorization", "token "+os.Getenv("GITHUB_TOKEN"))
+
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer resp.Body.Close()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+ if resp.StatusCode > 299 {
+ log.Fatal("non-OK response creating PR: %s", body)
+ }
+
+ log.Print("PR created: %s", body)
+}
diff --git a/internal/kokoro/synth/synth.sh b/internal/kokoro/synth/synth.sh
new file mode 100755
index 0000000..29bed65
--- /dev/null
+++ b/internal/kokoro/synth/synth.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e -x
+
+WORKING_BRANCH=synth-update
+
+cd $(dirname $0)/../../..
+
+should_create_pr=1
+git checkout -b $WORKING_BRANCH || {
+ # The branch already exists - assume there's an existing PR.
+ unset should_create_pr;
+
+ # Reset back to master
+ git checkout $WORKING_BRANCH;
+ git reset --hard origin/master;
+}
+
+pushd google-api-go-generator
+make all
+popd
+
+if [[ -z "$(git status --porcelain)"]]; then
+ echo "No changes today; exiting."
+ exit 0;
+fi
+
+echo "Pushing changes"
+
+commit_message="all: autogenerated update ($(date '+%Y-%m-%d'))"
+git commit --all -m "$commit_message"
+
+git push origin $WORKING_BRANCH:$WORKING_BRANCH -f
+
+if [ "$should_create_pr" ]; then
+ echo "Creating PR."
+ go run ./sendpr -title "$commit_message"
+fi
+
diff --git a/synth.py b/synth.py
new file mode 100644
index 0000000..70eb062
--- /dev/null
+++ b/synth.py
@@ -0,0 +1,19 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import subprocess
+import logging
+
+logging.basicConfig(level=logging.DEBUG)
+subprocess.run(['./internal/kokoro/synth.sh'])