forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-readme.sh
executable file
·140 lines (115 loc) · 4.59 KB
/
setup-readme.sh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
# Usage: $0 <user> <repo> [draftxml ...]
user="$1"
repo="$2"
default_branch="${DEFAULT_BRANCH:-$("$(dirname "$0")/default-branch.py")}"
shift 2
githubio="https://${user}.github.io/${repo}/#go"
function fixup_other_md() {
markdown=(LICENSE.md CONTRIBUTING.md)
s='s~{WG_NAME}~'"$1"'~g'
s="$s"';s~{GITHUB_USER}~'"$user"'~g'
s="$s"';s~{GITHUB_REPO}~'"$repo"'~g'
s="$s"';s~{GITHUB_BRANCH}~'"$default_branch"'~g'
sed -i~ -e "$s" "${markdown[@]}"
for i in "${markdown[@]}"; do
rm -f "$i"~
done
}
function get_title() {
if hash xmllint >/dev/null 2>&1; then
t=($(xmllint --xpath '/rfc/front/title/text()' "$1"))
else
# sed kludge if xmllint isn't available
t=($(sed -e '/<title[^>]*>/,/<\/title>/{s/.*<title[^>]*>//;/<\/title>/{s/<\/title>.*//;H;x;q;};H;};d' "$1"))
fi
# haxx: rely on bash parameter normalization to remove redundant whitespace
echo "${t[*]}"
}
first=true
for d in "$@"; do
fullname="${d%.xml}"
author=$(echo "${fullname}" | cut -f 2 -d - -)
wg=$(echo "${fullname}" | cut -f 3 -d - -)
wgupper=$(echo "${wg}" | tr 'a-z' 'A-Z')
title=$(get_title "$d")
if "$first"; then
fixup_other_md "$wg"
if [ "$author" = "ietf" ]; then
status="Working Group"
status_full="IETF [${wgupper} Working Group](https://datatracker.ietf.org/wg/${wg}/documents/) Internet-Draft"
else
status="Individual"
status_full="individual Internet-Draft"
fi
if [ $# -gt 1 ]; then
echo "# ${wgupper} Drafts"
status_full="${status_full}s"
else
echo "# $title"
status_full="the ${status_full}, \"${title}\""
fi
echo
echo "This is the working area for ${status_full}."
wg_all="$wg"
first=false
elif [ "$wg" != "$wg_all" ]; then
wg_all=""
fi
if [ $# -gt 1 ]; then
echo
echo "## $title"
fi
echo
echo "* [Editor's Copy](${githubio}.${fullname}.html)"
echo "* [Datatracker Page](https://datatracker.ietf.org/doc/${fullname})"
echo "* [${status} Draft](https://datatracker.ietf.org/doc/html/${fullname})"
echo "* [Compare Editor's Copy to ${status} Draft](${githubio}.${fullname}.diff)"
done
cat <<EOF
## Contributing
See the
[guidelines for contributions](https://github.com/${user}/${repo}/blob/${default_branch}/CONTRIBUTING.md).
Contributions can be made by creating pull requests.
The GitHub interface supports creating pull requests using the Edit (✏) button.
## Command Line Usage
Formatted text and HTML versions of the draft can be built using \`make\`.
\`\`\`sh
$ make
\`\`\`
Command line usage requires that you have the necessary software installed. See
[the instructions](https://github.com/martinthomson/i-d-template/blob/main/doc/SETUP.md).
EOF
if [ -n "$wg_all" ]; then
api="https://datatracker.ietf.org"
wgmeta="${api}/api/v1/group/group/?format=xml&acronym=${wg_all}"
tmp=$(mktemp)
trap 'rm -f $tmp' EXIT
if hash xmllint && curl -SsLf "$wgmeta" -o "$tmp" &&
[ "$(xmllint --xpath '/response/meta/total_count/text()' "$tmp")" == "1" ]; then
group_name="$(xmllint --xpath '/response/objects/object[1]/name/text()' "$tmp")"
group_type_url="$(xmllint --xpath '/response/objects/object[1]/type/text()' "$tmp")"
# Getting the abbreviation for the group type is pure haxx
group_type_abbr="${group_type_url%/}"
group_type_abbr="${group_type_abbr##*/}"
group_type="$(curl -Ssf "${api}${group_type_url}?format=xml" | \
xmllint --xpath '/object/verbose_name/text()' /dev/stdin)"
ml="$(xmllint --xpath '/response/objects/object[1]/list_email/text()' "$tmp")"
ml_arch="$(xmllint --xpath '/response/objects/object[1]/list_archive/text()' "$tmp")"
ml_sub="$(xmllint --xpath '/response/objects/object[1]/list_subscribe/text()' "$tmp")"
sed -i -e '/^## Working Group Info/,$ {1s///;t;d;}' CONTRIBUTING.md
cat >>CONTRIBUTING.md <<EOF
## Working Group Information
Discussion of this work occurs on the [${group_name}
${group_type} mailing list](mailto:${ml})
([archive](${ml_arch}),
[subscribe](${ml_sub})).
In addition to contributions in GitHub, you are encouraged to participate in
discussions there.
**Note**: Some working groups adopt a policy whereby substantive discussion of
technical issues needs to occur on the mailing list.
You might also like to familiarize yourself with other
[${group_type} documents](https://datatracker.ietf.org/${group_type_abbr}/${wg_all}/documents/).
EOF
fi
fi