1#!/bin/bash
2
3#   Copyright © 2016 Zetok Zalbavar <zetok@openmailbox.org>
4#   Copyright © 2019 by The qTox Project Contributors
5#
6#   This file is part of qTox, a Qt-based graphical interface for Tox.
7#   qTox is libre software: you can redistribute it and/or modify
8#   it under the terms of the GNU General Public License as published by
9#   the Free Software Foundation, either version 3 of the License, or
10#   (at your option) any later version.
11#
12#   qTox is distributed in the hope that it will be useful,
13#   but WITHOUT ANY WARRANTY; without even the implied warranty of
14#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#   GNU General Public License for more details.
16#
17#   You should have received a copy of the GNU General Public License
18#   along with qTox.  If not, see <http://www.gnu.org/licenses/>
19
20# Script for merging pull requests. Works only when there are no merge
21# conflicts. Assumes that working dir is a qTox git repo.
22#
23# Requires SSH key that github accepts and GPG set to sign merge commits.
24
25# usage:
26#   ./$script $pr_number $optional_message
27#
28#
29# $pr_number – number of the PR as shown on GH
30# $optional_message – message that is going to be put in merge commit,
31#       before the appended shortlog.
32#
33
34set -e -o pipefail
35
36readonly PR="${1###}"
37
38# make sure to add newlines to the message, otherwise merge message
39# will not look well
40if [[ ! -z $2 ]]
41then
42    readonly OPT_MSG="
43$2
44"
45fi
46
47source_functions() {
48    local fns_file="tools/lib/PR_bash.source"
49    source $fns_file
50}
51
52main() {
53    local remote_name="upstream"
54    local merge_branch="merge"
55    local base_branch # because assigning on the same line will break error code parsing.. http://www.tldp.org/LDP/abs/html/localvar.html
56    base_branch=$(git symbolic-ref HEAD --short)
57
58    source_functions
59    exit_if_not_pr $PR
60    add_remote
61    get_sources
62
63    merge git merge -S \
64        && after_merge_msg $merge_branch \
65        || after_merge_failure_msg $merge_branch
66}
67main
68