4 # ============LICENSE_START================================================
6 # =========================================================================
7 # Copyright (C) 2021-2022 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==================================================
25 SCRIPT_NAME=`basename $0`
31 echo "$SCRIPT_NAME - generates a new commit or a patch on an existing commit for PF releases"
33 echo " usage: $SCRIPT_NAME [-options]"
36 echo " -h - this help message"
37 echo " -l location - the location of the policy framework repos on the file system,"
38 echo " defaults to '$repo_location'"
39 echo " -r repo - the policy repo to which to commit"
40 echo " -i issue-id - issue ID in the format POLICY-nnnn"
41 echo " -e commit-header - the header for the commit"
42 echo " -m commit-message - the message body for the commit"
45 echo " $SCRIPT_NAME -l /home/git/onap -r policy/pap -i POLICY-1234 -e commit-header -m commit-message"
46 echo " create a new commit or update an existing commit on policy/pap with the given details"
53 update_drools_pdp=false
57 while getopts "hl:r:i:e:m:" opt
67 specified_repo=$OPTARG
76 commit_message=$OPTARG
87 echo "no arguments were specified"
91 if [[ -z "$repo_location" ]]
93 echo "policy repo location not specified on -l flag"
96 if ! [ -d "$repo_location" ]
98 echo "policy repo location '$repo_location' not found"
102 if [ -z "$specified_repo" ]
104 echo "repo not specified on -r flag"
108 if [ -z "$issue_id" ]
110 echo "issue_id not specified on -i flag"
114 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
116 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
120 if [ -z "$commit_header" ]
122 echo "commit_header not specified on -e flag"
126 if [ -z "$commit_message" ]
128 echo "commit_message not specified on -m flag"
132 git -C $repo_location/$specified_repo status | grep '^Your branch is up to date' > /dev/null 2>&1
135 if [ $return_code -eq 0 ]
137 echo "generating commit '$commit_header' . . ."
139 commit_msg_temp_file=$(mktemp)
140 echo "$commit_header" > $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 "*** This commit is generated by a PF release script ***" >> $commit_msg_temp_file
145 echo "" >> $commit_msg_temp_file
146 echo "Issue-ID: $issue_id" >> $commit_msg_temp_file
148 git -C $repo_location/$specified_repo add .
149 git -C $repo_location/$specified_repo commit -s -F "$commit_msg_temp_file"
150 rm $commit_msg_temp_file
152 echo "commit '$commit_header' generated"
154 echo "updating commit '$commit_header' . . ."
156 git -C $repo_location/$specified_repo add .
157 git -C $repo_location/$specified_repo commit -as --amend --no-edit
159 echo "commit '$commit_header' updated"
162 echo "sending commit '$commit_header' to gerrit . . ."
163 git -C $repo_location/$specified_repo review
164 echo "commit '$commit_header' sent to gerrit . . ."