4 # ============LICENSE_START================================================
6 # =========================================================================
7 # Copyright (C) 2021 Nordix Foundation.
8 # =========================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END==================================================
23 SCRIPT_NAME=`basename $0`
29 echo "$SCRIPT_NAME - generates a new commit or a patch on an existing commit for PF releases"
31 echo " usage: $SCRIPT_NAME [-options]"
34 echo " -h - this help message"
35 echo " -l location - the location of the policy framework repos on the file system,"
36 echo " defaults to '$repo_location'"
37 echo " -r repo - the policy repo to which to commit"
38 echo " -i issue-id - issue ID in the format POLICY-nnnn"
39 echo " -e commit-header - the header for the commit"
40 echo " -m commit-message - the message body for the commit"
43 echo " $SCRIPT_NAME -l /home/git/onap -r policy/pap -i POLICY-1234 -e commit-header -m commit-message"
44 echo " create a new commit or update an existing commit on policy/pap with the given details"
51 update_drools_pdp=false
55 while getopts "hl:r:i:e:m:" opt
65 specified_repo=$OPTARG
74 commit_message=$OPTARG
85 echo "no arguments were specified"
89 if [[ -z "$repo_location" ]]
91 echo "policy repo location not specified on -l flag"
94 if ! [ -d "$repo_location" ]
96 echo "policy repo location '$repo_location' not found"
100 if [ -z "$specified_repo" ]
102 echo "repo not specified on -r flag"
106 if [ -z "$issue_id" ]
108 echo "issue_id not specified on -i flag"
112 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
114 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
118 if [ -z "$commit_header" ]
120 echo "commit_header not specified on -e flag"
124 if [ -z "$commit_message" ]
126 echo "commit_message not specified on -m flag"
130 git -C $repo_location/$specified_repo status | grep '^Your branch is up to date' > /dev/null 2>&1
133 if [ $return_code -eq 0 ]
135 echo "generating commit '$commit_header' . . ."
137 commit_msg_temp_file=$(mktemp)
138 echo "$commit_header" > $commit_msg_temp_file
139 echo "" >> $commit_msg_temp_file
140 echo "*** This commit is generated by a PF release script ***" >> $commit_msg_temp_file
141 echo "" >> $commit_msg_temp_file
142 echo "$commit_message" >> $commit_msg_temp_file
143 echo "" >> $commit_msg_temp_file
144 echo "Issue-ID: $issue_id" >> $commit_msg_temp_file
146 git -C $repo_location/$specified_repo add .
147 git -C $repo_location/$specified_repo commit -s -F "$commit_msg_temp_file"
148 rm $commit_msg_temp_file
150 echo "commit '$commit_header' generated"
152 echo "updating commit '$commit_header' . . ."
154 git -C $repo_location/$specified_repo add .
155 git -C $repo_location/$specified_repo commit -as --amend --no-edit
157 echo "commit '$commit_header' updated"
160 echo "sending commit '$commit_header' to gerrit . . ."
161 git -C $repo_location/$specified_repo review
162 echo "commit '$commit_header' sent to gerrit . . ."