File: json-commit.sh

package info (click to toggle)
libreswan 4.3-1%2Bdeb11u4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,688 kB
  • sloc: ansic: 108,293; sh: 25,973; xml: 11,756; python: 10,230; makefile: 1,580; javascript: 1,353; yacc: 825; sed: 647; perl: 584; lex: 159; awk: 156
file content (118 lines) | stat: -rwxr-xr-x 2,539 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh

if test $# -lt 1 ; then
    cat >> /dev/stderr <<EOF

Usage:

    $0 <gitrev> [ <repodir> ]

Dump <gitrev> from <repodir> as raw json using a format similar to:

    https://developer.github.com/v3/git/commits/

Where:

    included:
        author
        committer

    missing:
        sha (see hash)
        tree
        url
        verification
        message (see subject)
	parents (see parent_hashes)

    non-standard:
        hashes
        parent_hashes
	interesting
	subject

EOF
    exit 1
fi

webdir=$(cd $(dirname $0) && pwd)
gitrev=$1 ; shift
if test $# -gt 0 ; then
    cd $1
    shift
fi

if ! git show --no-patch --format= ${gitrev} -- > /dev/null 2>&1 ; then
    echo "invalid: ${gitrev}" 1>&2
    exit 1
fi

key_format() {
    key=$1 ; shift
    format=$1 ; shift
    git show --no-patch --format="${format}" ${gitrev} | \
	jq --raw-input \
	   --arg key "$key" \
	   '{ ($key): . }'
}

commiter_format() {
    key=$1 ; shift
    format=$1 ; shift
    git show --no-patch --format=%${format}I%n%${format}n%n%${format}e ${gitrev} \
	| jq --raw-input . \
	| jq -s \
	     --arg key $key \
	     '{
    ($key): {
        date: .[0],
        name: .[1],
        email: .[2],
    },
}'
}

(
    # Output the parent commits as a list.
    #
    # %P puts all the hashes on a single line separated by spaces, the
    # %for-loop converts that to one hash per line.  Change it to sed
    # %...?

    for parent in $(git show --no-patch --format=%P "${gitrev}^{commit}") ; do
	echo ${parent} | jq --raw-input '.'
    done | jq -s '{ parent_hashes: . }'

    # Create the message, github seems to strip trailing new lines.
    #
    #    git show --no-patch --format=%B ${gitrev} \
    #	| jq -s --raw-input \
    #	     '{ message: sub("\n\n$";""), }'

    # Add an "interesting" commit attribute.  Only "interesting"
    # commits get tested.
    #
    # git-interesting outputs either "false", "true" or "reason:
    # details" (for really interesting stuff).  Need to convert the
    # last one to proper json:

    interesting=$(${webdir}/git-interesting.sh ${gitrev})
    case "${interesting}" in
	*:* )
	    # convert 'reason: details' -> '"reason"'
	    interesting=$(echo ${interesting} | sed -e 's/\(.*\):.*/"\1"/')
	    ;;
    esac
    jq --null-input \
       --argjson interesting "${interesting}" \
       '{ interesting: $interesting }'

    # Rest are easy to deal with.

    key_format subject %s
    key_format hash %H

    commiter_format author a
    commiter_format committer c

) | jq -s 'add'