blob: a62cf49379f04e2f1e1c7e5a436807febe642acb [file] [log] [blame]
liamfallona14dffc2021-12-03 18:41:39 +00001#!/bin/bash
liamfallona771e2d2021-12-02 16:00:28 +00002
3#
4# ============LICENSE_START================================================
5# ONAP
6# =========================================================================
liamfallon81c2c512021-12-16 12:56:37 +00007# Copyright (C) 2021-2022 Nordix Foundation.
liamfallona771e2d2021-12-02 16:00:28 +00008# =========================================================================
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
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
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==================================================
21#
22
liamfallond7d9a662022-03-01 21:01:03 +000023SCRIPT_NAME=$(basename "$0")
liamfallona771e2d2021-12-02 16:00:28 +000024repo_location="./"
25
26usage()
27{
28 echo ""
29 echo "$SCRIPT_NAME - generates a new commit or a patch on an existing commit for PF releases"
30 echo ""
31 echo " usage: $SCRIPT_NAME [-options]"
32 echo ""
33 echo " 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"
41 echo ""
42 echo " example:"
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"
45 exit 255;
46}
47
liamfallona771e2d2021-12-02 16:00:28 +000048while getopts "hl:r:i:e:m:" opt
49do
50 case $opt in
51 h)
52 usage
53 ;;
54 l)
55 repo_location=$OPTARG
56 ;;
57 r)
58 specified_repo=$OPTARG
59 ;;
60 i)
61 issue_id=$OPTARG
62 ;;
63 e)
64 commit_header=$OPTARG
65 ;;
66 m)
67 commit_message=$OPTARG
68 ;;
69 \?)
70 usage
71 exit 1
72 ;;
73 esac
74done
75
76if [ $OPTIND -eq 1 ]
77then
78 echo "no arguments were specified"
79 usage
80fi
81
82if [[ -z "$repo_location" ]]
83then
84 echo "policy repo location not specified on -l flag"
85 exit 1
86fi
87if ! [ -d "$repo_location" ]
88then
89 echo "policy repo location '$repo_location' not found"
90 exit 1
91fi
92
93if [ -z "$specified_repo" ]
94then
95 echo "repo not specified on -r flag"
96 exit 1
97fi
98
99if [ -z "$issue_id" ]
100then
101 echo "issue_id not specified on -i flag"
102 exit 1
103fi
104
105if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
106then
107 echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
108 exit 1
109fi
110
111if [ -z "$commit_header" ]
112then
113 echo "commit_header not specified on -e flag"
114 exit 1
115fi
116
117if [ -z "$commit_message" ]
118then
119 echo "commit_message not specified on -m flag"
120 exit 1
121fi
122
liamfallond7d9a662022-03-01 21:01:03 +0000123git -C "$repo_location/$specified_repo" status | grep '^Your branch is up to date' > /dev/null 2>&1
liamfallona771e2d2021-12-02 16:00:28 +0000124return_code=$?
125
126if [ $return_code -eq 0 ]
127then
128 echo "generating commit '$commit_header' . . ."
129
130 commit_msg_temp_file=$(mktemp)
liamfallond7d9a662022-03-01 21:01:03 +0000131 {
132 echo "$commit_header"
133 echo ""
134 echo "$commit_message"
135 echo ""
136 echo "*** This commit is generated by a PF release script ***"
137 echo ""
138 echo "Issue-ID: $issue_id"
139 } > "$commit_msg_temp_file"
liamfallona771e2d2021-12-02 16:00:28 +0000140
liamfallond7d9a662022-03-01 21:01:03 +0000141 git -C "$repo_location/$specified_repo" add .
142 git -C "$repo_location/$specified_repo" commit -s -F "$commit_msg_temp_file"
143 rm "$commit_msg_temp_file"
liamfallona771e2d2021-12-02 16:00:28 +0000144
145 echo "commit '$commit_header' generated"
146else
147 echo "updating commit '$commit_header' . . ."
148
liamfallond7d9a662022-03-01 21:01:03 +0000149 git -C "$repo_location/$specified_repo" add .
150 git -C "$repo_location/$specified_repo" commit -as --amend --no-edit
liamfallona771e2d2021-12-02 16:00:28 +0000151
152 echo "commit '$commit_header' updated"
153fi
154
155echo "sending commit '$commit_header' to gerrit . . ."
liamfallond7d9a662022-03-01 21:01:03 +0000156git -C "$repo_location/$specified_repo" review
liamfallona771e2d2021-12-02 16:00:28 +0000157echo "commit '$commit_header' sent to gerrit . . ."
158
159