-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew
More file actions
81 lines (68 loc) · 1.91 KB
/
new
File metadata and controls
81 lines (68 loc) · 1.91 KB
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
#!/usr/bin/env sh
set -u
set -e
git_inited(){
git rev-parse --is-inside-work-tree >/dev/null 2>&1
}
get_name_from_git(){
name=`gh repo view --json name --jq .name`
}
last_path_part(){
local p="$1"
p="${p%/}"; echo "${p##*/}"
}
if [ $# = 0 ]; then
if git_inited; then
owner=`gh repo view --json owner --jq .owner.login`
get_name_from_git
REPO="$owner/$name"
pure_name=$name
name=.
else
echo "neither getting owner/repo argument nor in a git repo"
exit 1
fi
else
REPO=$1
owner="${REPO%%/*}"
name="${REPO#*/}"
pure_name=$name
[ -z "$name" ] && {
name="$(last_path_part `realpath .`)"
REPO="$REPO$name"
pure_name=$name
name="../$name"
}
[ -z "$owner" ] && {
echo "bad argument, expect owner/name" >&2
exit 1
}
if ! git_inited; then
DIR="$(dirname "$0")"
LOC_TEMPL="$DIR/../template"
if [ -d "$LOC_TEMPL" ]; then
cp -r "$LOC_TEMPL" "$name"
else
gh repo clone "$owner/template" "$name" -- --quiet || true
fi
fi
fi
git --git-dir="$name/.git" remote remove origin || true
gh repo new --public --source "$name" "$REPO"
gh api -X put /repos/$REPO/subscription -F "subscribed=true" || echo "warning: subscript to $name failed"
if [[ "$name" != "." && "$name" != '..*' && ! -f $name/README.md ]]; then
if [ -f ${name}/${pure_name}.nimble ]; then
desc=$(pcregrep -o1 '\s*description\s*=\s*"([^"]+)"' ${name}/${pure_name}.nimble)
else
desc=""
fi
echo "
# ${pure_name}
[](https://github.com/${REPO}/actions/workflows/ci.yml)
[](https://github.com/${REPO}/actions/workflows/docs.yml)
<!--[](https://github.com/${REPO}/commits/)-->
---
[Docs](https://${owner}.github.io/${pure_name}/)
${desc}
" > "$name/README.md"
fi