1#!/bin/bash
2#
3# Given a Wireshark issue ID, fetch its title and prepare an entry suitable
4# for pasting into the release notes. Requires curl and jq.
5#
6# Usage: gen-bugnote <issue number>
7#
8# Copyright 2013 Gerald Combs
9#
10# SPDX-License-Identifier: GPL-2.0-or-later
11#
12
13gitlab_issue_url_pfx="https://gitlab.com/api/v4/projects/wireshark%2Fwireshark/issues"
14issue_id="${1#\#}" # Strip leading "#"
15
16case "$OSTYPE" in
17    darwin*)
18        clipboard_cmd="pbcopy -Pascii"
19        ;;
20    cygwin*)
21        clipboard_cmd="cat > /dev/clipboard"
22        ;;
23    linux*)
24        clipboard_cmd="xsel --clipboard"
25        ;;
26    *)
27        echo "Unable to copy to clipboard"
28        clipboard_cmd="cat > /dev/null"
29        ;;
30esac
31
32if [ -z "$issue_id" ] ; then
33    echo "Usage: $( basename "$0" ) <issue id>"
34    exit 1
35fi
36
37issue_title=$(
38    curl -s -o - "${gitlab_issue_url_pfx}/$issue_id" \
39    | jq --raw-output '.title'
40    )
41
42echo -e "* $issue_title wsbuglink:${issue_id}[].\\n" \
43    | $clipboard_cmd
44
45echo "Copied $issue_id: $issue_title"
46