1#!/bin/bash
2# Copyright 2021 Google LLC
3
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7
8#     https://www.apache.org/licenses/LICENSE-2.0
9
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# If this is a github job, configure git
17if [[ $GITHUB_JOB ]]; then
18    git config --global user.name 'Yoshi Automation'
19    git config --global user.email '[email protected]'
20fi
21
22while read api;
23do
24    name=`echo $api | cut -d '.' -f 1`
25    API_SUMMARY_PATH=temp/$name.verbose
26
27    if [[ ! -f "temp/$name.sha" ]]; then
28        if [ $name = "index" ]; then
29            git add '../docs/dyn/index.md'
30            commitmsg='chore: update docs/dyn/index.md'
31        else
32            git add '../googleapiclient/discovery_cache/documents/'$name'.*.json'
33            git add '../docs/dyn/'$name'_*.html'
34            if [[ -f "$API_SUMMARY_PATH" ]]; then
35                commitmsg=`cat $API_SUMMARY_PATH`
36            else
37                commitmsg='chore('$name'): update the api'
38            fi
39        fi
40        git commit -m "$commitmsg"
41        git rev-parse HEAD>temp/$name'.sha'
42        git reset
43    fi
44done < temp/changed_files
45
46# Add untracked files
47git add "../googleapiclient/discovery_cache/documents/*.json"
48git add "../docs/dyn/*.html"
49commitmsg='chore(docs): Add new discovery artifacts and reference documents'
50git commit -m "$commitmsg"
51
52exit 0
53