forked from chenchongbiao/dbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbuilder-hub
executable file
·138 lines (116 loc) · 3.42 KB
/
dbuilder-hub
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
#!/bin/bash
# 尝试使用未设置值的变量,脚本将停止执行
set -o nounset
org="deepin-community"
init_config()
{
# github_id=$(jq -r ".github.id" $config_file)
# if [[ -z $github_id ]]; then
# echo "Github ID为,请输入数据: "
# read github_id
# tmp=$(mktemp)
# jq --indent 4 --arg github_id $github_id '.github.id=$github_id' $config_file > $tmp && mv $tmp $config_file
# fi
# if [ -e "/tmp/github_token" ]; then
# token=$(cat "/tmp/github_token")
# else
# echo "Github Token为空,请输入数据: "
# read token
# echo "$token" > /tmp/github_token
# fi
# 获取gh auth status的输出
output=$(gh auth status 2>&1)
# 检查输出中是否包含You are not logged
if [[ $output == *"You are not logged"* ]]; then
# 如果包含,说明没有登录,如果不包含,说明已经登录
echo "你没有登录GitHub CLI"
gh auth login
fi
}
branch()
{
branch="topic-$2"
tmp=$(mktemp)
jq --indent 4 --arg branch $branch '.github.branch=$branch' $config_file > $tmp && mv $tmp $config_file
}
issue()
{
issue="$2"
tmp=$(mktemp)
jq --indent 4 --arg issue $issue '.github.issue=$issue' $config_file > $tmp && mv $tmp $config_file
}
diff_source()
{
source dbuilder-source pre "${2}"
repo_path="$psource_path/repo"
source_path="$psource_path/${psource}"
cd $psource_path
# clone代码
if [ ! -e "repo" ]; then
gh repo fork --clone "$org/$psource" -- repo
cd $repo_path && gh repo set-default "$org/$psource"
git pull upstream master --rebase
fi
cp -r $repo_path/.{git,github} $source_path
cp -r $repo_path/debian/deepin $source_path/debian
}
push_source()
{
diff_source "" "$2"
branch=$(jq -r ".github.branch" $config_file)
if [[ $branch == "topic-none" ]]; then
echo "Github 仓库推送分支为空(默认使用master): "
branch="master"
fi
issue=$(jq -r ".github.issue" $config_file)
source_version=$(cat "$dsc_file" | grep -oP '^Version: \S+$' | cut -d ' ' -f 2)
if [[ "$source_version" == *-* ]] ; then
upstream_version=$(echo "$source_version" | rev | cut -d '-' -f 2- | rev)
else
upstream_version="$source_version"
fi
upstream_version=$(echo "$upstream_version" | tr ':~' '%_')
cd $source_path
# 如果分支不存在就创建
if ! git branch | grep -q $branch; then
git branch $branch
fi
git switch $branch
if [ -e "$source_path/debian/patches" ]; then
git add -fN debian/patches
if git --no-pager diff debian/patches >/dev/null ; then
read -p '请查看一下 patches: '
git add -f debian/patches
fi
fi
git add -f .
message="feat: update $psource to $upstream_version\n\n$description\n"
if [ ! "$issue" == "none" ]; then
message="$message\nIssue: $issue"
fi
message="$message\nLog: update repo"
echo -e "$message" | git commit --file=-
git push -f --set-upstream origin "$branch"
gh pr create -f
}
diff_source_from_my_repo()
{
init_config
source dbuilder-source get "${2}"
fork_repo "" "$psource"
diff_source "" "$2" "$github_id"
}
case "$1" in
branch)
branch "$@"
;;
issue)
issue "$@"
;;
diff)
diff_source "$@"
;;
push)
push_source "$@"
;;
esac