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"
50 while getopts "hl:r:i:e:m:" opt
60 specified_repo=$OPTARG
69 commit_message=$OPTARG
80 echo "no arguments were specified"
84 if [[ -z "$repo_location" ]]
86 echo "policy repo location not specified on -l flag"
89 if ! [ -d "$repo_location" ]
91 echo "policy repo location '$repo_location' not found"
95 if [ -z "$specified_repo" ]
97 echo "repo not specified on -r flag"
101 if [ -z "$issue_id" ]
103 echo "issue_id not specified on -i flag"
107 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
109 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
113 if [ -z "$commit_header" ]
115 echo "commit_header not specified on -e flag"
119 if [ -z "$commit_message" ]
121 echo "commit_message not specified on -m flag"
125 git -C "$repo_location/$specified_repo" status | grep '^Your branch is up to date' > /dev/null 2>&1
128 if [ $return_code -eq 0 ]
130 echo "generating commit '$commit_header' . . ."
132 commit_msg_temp_file=$(mktemp)
134 echo "$commit_header"
136 echo "$commit_message"
138 echo "*** This commit is generated by a PF release script ***"
140 echo "Issue-ID: $issue_id"
141 } > "$commit_msg_temp_file"
143 git -C "$repo_location/$specified_repo" add .
144 git -C "$repo_location/$specified_repo" commit -s -F "$commit_msg_temp_file"
145 rm "$commit_msg_temp_file"
147 echo "commit '$commit_header' generated"
149 echo "updating commit '$commit_header' . . ."
151 git -C "$repo_location/$specified_repo" add .
152 git -C "$repo_location/$specified_repo" commit -as --amend --no-edit
154 echo "commit '$commit_header' updated"
157 echo "sending commit '$commit_header' to gerrit . . ."
158 git -C "$repo_location/$specified_repo" review
159 echo "commit '$commit_header' sent to gerrit . . ."