-
Notifications
You must be signed in to change notification settings - Fork 66
/
test.sh
executable file
·669 lines (598 loc) · 23.4 KB
/
test.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#!/bin/sh
# shellcheck disable=SC2039,SC2164,SC2086,SC2103
#
# Shellcheck ignore list:
# - SC2039: In POSIX sh, 'local' is undefined.
# Rationale: Local makes for better code and works on many modern shells
# - SC2164: Use cd ... || exit in case cd fails.
# Rationale: We run this after creating the directory
# - SC2164: Use a ( subshell ) to avoid having to cd back.
# Rationale: We run this after creating the directory
#
#
# (C) Copyright 2016-2020 Diomidis Spinellis
#
# This file is part of gi, the Git-based issue management system.
#
# gi is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gi. If not, see <http://www.gnu.org/licenses/>.
#
# Display a test's result
message()
{
local okfail
okfail=$1
shift
if [ "$1" ] ; then
echo "$okfail $ntest - $*"
else
echo "$okfail $ntest - $testname"
fi |
sed "s/$gi_re/gi/"
}
ok()
{
message ok "$*"
}
fail()
{
printf "%d " "$ntest" >>"$TopDir/failure"
message fail "$*"
}
# Test specified command, which should succeed
try()
{
local exit_code
ntest=$((ntest + 1))
echo "Test $ntest: $*" >>"$TopDir/error.log"
"$@" >/dev/null 2>>"$TopDir/error.log"
exit_code=$?
cd .issues
if git status | grep 'not staged' >/dev/null ; then
fail staging "$*"
else
ok staging "$*"
fi
cd ..
start
if [ $exit_code = 0 ] ; then
ok "$*"
else
fail "$*"
fi
}
# Test specified command, which should fail
ntry()
{
ntest=$((ntest + 1))
if ! "$@" >/dev/null 2>&1 ; then
ok "fail $*"
else
fail "fail $*"
fi
}
# grep for the specified pattern, which should be found
# Does not increment ntest, because it is executed as a separate process
try_grep()
{
test -z "$testname" && echo "Test $ntest: grep $*" >>"$TopDir/error.log"
if tee input | grep "$@" >/dev/null 2>&1 ; then
ok "grep $*"
else
fail "grep $*"
echo 'Input:' >>"$TopDir/error.log"
cat input >>"$TopDir/error.log"
fi
}
# grep for the specified pattern, which should not be found
# Does not increment ntest, because it is executed as a separate process
try_ngrep()
{
test -z "$testname" && echo "Test $ntest: ! grep $*" >>"$TopDir/error.log"
if ! tee input | grep "$@" >/dev/null 2>&1 ; then
ok "not grep $1"
else
fail "not grep $1"
echo 'Input:' >>"$TopDir/error.log"
cat input >>"$TopDir/error.log"
fi
}
# Start a new test with the specified description
start()
{
ntest=$((ntest + 1))
testname="$*"
test -n "$testname" && echo "Test $ntest: $*" >>"$TopDir/error.log"
}
# Fold header continuation lines
header_continuation()
{
sed -n '
# Header
/^[^ ]/ {
# Print previous hold space
x
s/\n//g
/^./p
x
# Keep in hold space
h
}
# Continuation
/^[ ]/ {
# Append to hold space
H
}
$ {
# Print previous hold space
x
s/\n/ /g
/^./p
}
'
}
TopDir=$(mktemp -d)
{
jq --version || exit 1
curl --version
echo "Test artifacts saved in $TopDir"
} 1>&2
if command -v gdate ; then
DATEBIN="gdate"
else
DATEBIN="date"
fi
# Setup GitHub authentication token for Travis CI for curl version >= 7.55
# The GH_TOKEN environment variable with the secret token is specified in
# https://travis-ci.org/dspinellis/git-issue/settings
if [ -n "$GH_TOKEN" ] && curl --version | awk '/curl/{exit $2 >= "7.55" ? 0 : 1}' ; then
echo "Authorization: token $GH_TOKEN" >"$HOME/.token"
export GH_CURL_AUTH="Authorization: token $GH_TOKEN"
echo "Set GH_CURL_AUTH to $GH_CURL_AUTH using GH_TOKEN"
fi
echo 'TAP version 13'
ntest=0
gi="$(cd "$(dirname "$0")" && pwd)"/git-issue.sh
gi_re=$(echo "$gi" | sed 's/[^0-9A-Za-z]/\\&/g')
start sync-docs
GenFiles='git-issue.sh git-issue.1'
if ! git diff --quiet HEAD ; then
fail "Uncommitted files sync-docs test skipped and pending"
else
sh sync-docs.sh --no-user-agent
Status=$(git status --porcelain -- $GenFiles)
if [ -z "$Status" ]; then
ok "make sync-docs left $GenFiles as committed"
else
fail "make sync-docs changed $GenFiles"
git diff -- $GenFiles >>"$TopDir/error.log"
git checkout -- $GenFiles
fi
fi
cd "$TopDir"
mkdir testdir
cd testdir
git init > /dev/null 2>&1;
git config --local user.name "Joe"
git config --local user.email "[email protected]"
echo ".issues" > .gitignore
try "$gi" init
try "$gi" list
start ; ( cd .issues; git config --local user.name ) | try_grep "Joe"
start ; ( cd .issues; git config --local user.email ) | try_grep "[email protected]"
start ; "$gi" list "$issue" | try_ngrep .
# New
try "$gi" new -s 'First-issue'
start ; "$gi" list | try_grep 'First-issue'
# New with editor
export VISUAL='mv ../issue-desc '
# Empty summary/description should fail
touch issue-desc
ntry "$gi" new
cat <<EOF >issue-desc
Second issue
Line in description
EOF
try "$gi" new
issue=$("$gi" list | awk '/Second issue/{print $1}')
issue2=$("$gi" list | awk '/First-issue/{print $1}')
# Show
start ; "$gi" show "$issue" | try_grep 'Second issue'
start ; "$gi" show "$issue" | try_grep 'Line in description'
start ; "$gi" show "$issue" | try_grep '^Author:'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Tags:[ ]*open'
ntry "$gi" show xyzzy
# Edit
# Unmodified issue should fail
ntry "$gi" edit "$issue"
cat <<EOF >issue-desc
Second issue
Modified line in description
EOF
try "$gi" edit "$issue"
start ; "$gi" show "$issue" | try_grep 'Second issue'
start ; "$gi" show "$issue" | try_grep 'Modified line in description'
start ; "$gi" show "$issue" | try_ngrep 'Line in description'
export VISUAL=
# Comment
start
cat <<EOF >comment
Comment line
another line
EOF
export VISUAL='mv ../comment '; try "$gi" comment "$issue"
export VISUAL=
start ; "$gi" show -c "$issue" | try_grep 'another line'
# Comment editing
start
cat <<EOF >comment
Comment first line
comment second line
EOF
commentsha=$("$gi" show -c "$issue" | awk '/comment/{print $2}')
export VISUAL='mv ../comment '; try "$gi" edit -c "$commentsha"
# Try passing issue sha as comment sha
export VISUAL='mv ../comment '; ntry "$gi" edit -c "$issue"
export VISUAL=
start ; "$gi" show -c "$issue" | try_grep 'comment second line'
start ; "$gi" show -c "$issue" | try_ngrep 'another comment line'
# Assign
try "$gi" assign "$issue" [email protected]
ntry "$gi" assign "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_grep '^Assigned-to:[ ][email protected]'
try "$gi" assign "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_grep '^Assigned-to:.*[email protected]'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Assigned-to:.*[email protected]'
try "$gi" assign -r "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_ngrep '^Assigned-to:.*[email protected]'
ntry "$gi" assign -r "$issue" [email protected]
try "$gi" assign -r "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_ngrep '^Assigned-to:.*[email protected]'
try "$gi" assign "$issue" [email protected]
# Milestone
ntry "$gi" list ver2
try "$gi" milestone "$issue" ver2
start ; "$gi" list ver2 | try_grep "$issue"
start ; "$gi" show "$issue" | try_grep '^Milestone:[ ]ver2'
try "$gi" milestone "$issue" ver2
try "$gi" milestone "$issue" ver3
start ; "$gi" show "$issue" | try_grep '^Milestone:[ ]ver3'
start ; "$gi" show "$issue" | try_ngrep ver2
ntry "$gi" milestone -r "$issue" foo
try "$gi" milestone -r "$issue"
start ; "$gi" show "$issue" | try_ngrep ver3
# Weight
ntry "$gi" weight "$issue" l33t
ntry "$gi" weight -r "$issue"
try "$gi" weight "$issue" 1337
start ; "$gi" show "$issue" | try_grep 1337
try "$gi" weight -r "$issue"
start ; "$gi" show "$issue" | try_ngrep 1337
# Due Date
ntry "$gi" duedate "$issue" someday
ntry "$gi" duedate -r "$issue"
ntry "$gi" duedate -r "$issue" someday
start ; "$gi" duedate "$issue" yesterday | try_grep Warning
try "$gi" duedate "$issue" tomorrow
start ; "$gi" show "$issue" | try_grep "$($DATEBIN --date=tomorrow --rfc-3339=date)"
try "$gi" duedate -r "$issue"
start ; "$gi" show "$issue" | try_ngrep 'Due Date'
# Time Spent/Time Estimate
ntry "$gi" timespent "$issue" alot
ntry "$gi" timespent -r "$issue"
ntry "$gi" timespent -r "$issue" alot
ntry "$gi" timeestimate "$issue" alot
ntry "$gi" timeestimate -r "$issue"
ntry "$gi" timeestimate -r "$issue" 3months
try "$gi" timespent "$issue" 2hours
start ; "$gi" show "$issue" | try_grep '^Time Spent: 02 hours '
try "$gi" timespent -a "$issue" 3hours
start ; "$gi" show "$issue" | try_grep '^Time Spent: 05 hours '
try "$gi" timeestimate "$issue" 3days
try "$gi" timespent -a "$issue" 15minutes
# start ; "$gi" show "$issue" | try_grep 'Time Spent/Time Estimated: 05 hours 15 minutes \?/ \?3 days'
try "$gi" timespent -r "$issue"
start ; "$gi" show "$issue" | try_grep 'Time Estimate: 3 days'
# Watchers
try "$gi" watcher "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_grep '^Watchers:[ ][email protected]'
try "$gi" watcher "$issue" [email protected]
ntry "$gi" watcher "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_grep '^Watchers:.*[email protected]'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Watchers:.*[email protected]'
try "$gi" watcher -r "$issue" [email protected]
start ; "$gi" show "$issue" | header_continuation | try_ngrep '^Watchers:.*[email protected]'
try "$gi" watcher "$issue" [email protected]
# Tags (most also tested through watchers)
try "$gi" tag "$issue" feature
start ; "$gi" show "$issue" | header_continuation | try_grep '^Tags:.*feature'
ntry "$gi" tag "$issue" feature
# List by tag
start ; "$gi" list feature | try_grep 'Second issue'
start ; "$gi" list open | try_grep 'First-issue'
start ; "$gi" list feature | try_ngrep 'First-issue'
try "$gi" tag -r "$issue" feature
start ; "$gi" list feature 2>/dev/null | try_ngrep 'Second issue'
try "$gi" tag "$issue" feature
# Long list
start ; "$gi" list -l oneline feature | try_grep 'Second issue'
start ; "$gi" list -l oneline feature | try_ngrep 'First-issue'
start ; "$gi" list -l "Tags:%T" | try_grep 'feature'
try "$gi" milestone "$issue" ver2
try "$gi" weight "$issue" 99
start ; "$gi" list -l full | try_grep 'ver2'
start ; "$gi" list -l compact | try_grep 'Weight: 99'
try "$gi" milestone -r "$issue"
# Long list ordering
ntry "$gi" list -l short -o "%iA"
start ; "$gi" list -l oneline -o "%D" | head -n 1 | try_grep 'First-issue'
start ; "$gi" list -l oneline -o "%D" -r | head -n 1 | try_grep 'Second issue'
start ; "$gi" list -l short -o "%T" | head -n 4 | try_grep 'feature'
# Filter-apply
cat <<EOF >test-filter.sh
#!/bin/sh
echo "Line added by test-filter" >> description
EOF
chmod +x test-filter.sh
start ; "$gi" filter-apply test-filter.sh | try_grep "Filter applied"
start ; "$gi" show "$issue" | try_grep "Line added by test-filter"
# Reset changes
"$gi" git checkout -- .
# close
try "$gi" close "$issue"
start ; "$gi" list | try_ngrep 'Second issue'
start ; "$gi" list closed | try_grep 'Second issue'
# log
try "$gi" log
start ; n=$("$gi" log | tee foo | grep -c gi:)
try test "$n" -ge 18
# clone
# Required in order to allow a push to a non-bare repo
"$gi" git config --add receive.denyCurrentBranch ignore
cd ..
rm -rf testdir2
mkdir testdir2
cd testdir2
git clone ../testdir/.issues/ 2>/dev/null
start ; "$gi" show "$issue" | header_continuation | try_grep '^Watchers:.*[email protected]'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Tags:.*feature'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Assigned-to:.*[email protected]'
start ; "$gi" show "$issue" | try_grep 'Second issue'
start ; "$gi" show "$issue" | try_grep 'Modified line in description'
start ; "$gi" show "$issue" | try_grep '^Author:'
start ; "$gi" show "$issue" | header_continuation | try_grep '^Tags:.*closed'
# Push and pull
try "$gi" tag "$issue" cloned
try "$gi" push
cd ../testdir
"$gi" git reset --hard >/dev/null # Required, because we pushed to a non-bare repo
start ; "$gi" show "$issue" | header_continuation | try_grep '^Tags:.*cloned'
# Pull
try "$gi" tag "$issue" modified-upstream
cd ../testdir2
try "$gi" pull
"$gi" show "$issue" | try_grep modified-upstream
cd ../testdir
if [ -z "$GH_CURL_AUTH" ] ; then
echo "Skipping GitHub import/export tests due to lack of GitHub authentication token."
else
# Import
# GitHub
echo "Starting GitHub import tests..."
try "$gi" import github dspinellis git-issue-test-issues
start ; "$gi" list | try_grep 'An open issue on GitHub with a description and comments'
# Closed issues
start ; "$gi" list | try_grep -v 'A closed issue on GitHub without description'
start ; "$gi" list -a | try_grep 'A closed issue on GitHub without description'
# Description and comments
issue=$("$gi" list | awk '/An open issue on GitHub with a description and comments/ {print $1}')
start ; "$gi" show "$issue" | try_grep '^ *line 1$'
start ; "$gi" show "$issue" | try_grep '^ *line 2$'
start ; "$gi" show "$issue" | try_grep 'Line 3 with special characters "'\''<>|\$'
start ; "$gi" show -c "$issue" | try_grep '^ *comment 1 line 1$'
start ; "$gi" show -c "$issue" | try_grep '^ *comment 1 line 2$'
start ; "$gi" show -c "$issue" | try_grep '^ *comment 2$'
start ; "$gi" show -c "$issue" | try_grep '^ *comment 4$'
start ; "$gi" show "$issue" | try_grep '^GitHub issue: #[0-9]* at dspinellis/git-issue-test-issues$'
# Assignees and tags
issue=$("$gi" list | awk '/An open issue on GitHub with assignees and tags/ {print $1}')
start ; "$gi" show "$issue" | try_grep 'good first issue'
start ; "$gi" show "$issue" | header_continuation | try_grep 'Assigned-to:.*dspinellis'
start ; "$gi" show "$issue" | header_continuation | try_grep 'Assigned-to:.*louridas'
# Milestone
try "$gi" list ver3
# Import should be idempotent
before=$(cd .issues ; git rev-parse --short HEAD)
try "$gi" import github dspinellis git-issue-test-issues
after=$(cd .issues ; git rev-parse --short HEAD)
try test x"$before" = x"$after"
# Export
# create new repository to test issue exporting
echo "Trying to create GitHub repository..."
curl -H "$GH_CURL_AUTH" -s --data '{"name": "git-issue-test-export-'"$($DATEBIN -Is | tr ':+' '--')"'", "private": true}' --output ghrepo https://api.github.com/user/repos
if grep "git-issue-test-export" > /dev/null < ghrepo ; then
echo "Starting export tests..."
ghrepo=$(jq --raw-output '.full_name' < ghrepo | tr '/' ' ')
ghrepourl=$(jq --raw-output '.url' < ghrepo)
ghuser=$(jq --raw-output '.owner.login' < ghrepo)
# remove assignees to prevent notifications about test issues on GitHub
"$gi" assign -r "$issue" dspinellis > /dev/null 2>&1
"$gi" assign -r "$issue" louridas > /dev/null 2>&1
try "$gi" create -n "$issue" github $ghrepo
# Get the created issue
try "$gi" create -u "$(jq -r '.number' .issues/create-body)" "$issue" github $ghrepo
rm -f .issues/create-body .issues/create-header
# modify and export
try "$gi" create -n "$issue2" github $ghrepo
try "$gi" new -c "github $ghrepo" -s "Issue exported directly"
"$gi" assign "$issue2" "$ghuser" > /dev/null 2>&1
try "$gi" export github $ghrepo
start ; "$gi" export github $ghrepo | try_grep "Issue $issue.* not modified, skipping..."
# Test invalid assignee
"$gi" assign "$issue2" octocat > /dev/null 2>&1
start ; "$gi" export github $ghrepo | try_grep "Couldn't add assignee octocat. Skipping..."
"$gi" assign -r "$issue2" octocat > /dev/null 2>&1
# test milestone creation
"$gi" new -s "milestone issue" > /dev/null 2>&1
issue3=$("$gi" list | awk '/milestone issue/{print $1}')
"$gi" milestone "$issue3" ver4 > /dev/null 2>&1
"$gi" duedate "$issue3" week > /dev/null 2>&1
"$gi" timeestimate "$issue3" 3hours > /dev/null 2>&1
try "$gi" create -e "$issue3" github $ghrepo
try "$gi" exportall -a github $ghrepo
# Basic round-trip tests
echo "Starting GitHub round-trip test..."
cd ..
mkdir testdir3
cd testdir3
"$gi" init
try "$gi" import github $ghrepo
rissue=$("$gi" list | awk '/An open issue on GitHub with a description and comments/ {print $1}')
rissue2=$("$gi" list | awk '/milestone issue/{print $1}')
start ; "$gi" show "$rissue" | try_grep '^ *line 1'
start ; "$gi" show "$rissue" | try_grep '^ *line 2'
start ; "$gi" show "$rissue" | try_grep 'Line 3 with special characters "'\''<>|\$'
start ; "$gi" show -c "$rissue" | try_grep '^ *comment 1 line 1'
start ; "$gi" show -c "$rissue" | try_grep '^ *comment 1 line 2'
start ; "$gi" show -c "$rissue" | try_grep '^ *comment 2'
start ; "$gi" show -c "$rissue" | try_grep '^ *comment 4'
start ; "$gi" show "$rissue2" | try_grep '^Milestone: ver4'
rissue3=$("$gi" list | awk '/An open issue on GitHub with assignees and tags/ {print $1}')
start ; "$gi" show "$rissue3" | try_grep 'good first issue'
cd ../testdir
# delete repo
curl -H "$GH_CURL_AUTH" -s --request DELETE $ghrepourl |
grep "{" && printf "Couldn't delete repository.
You probably don't have delete permittions activated on the OAUTH token.\\nPlease delete %s manually." "$ghrepo"
else
echo "Couldn't create test repository. Skipping export tests."
fi
fi
# shellcheck disable=2153
if [ -z "$GL_CURL_AUTH" ] ; then
echo "Skipping GitLab import/export tests due to lack of GitLab authentication token."
else
# Import
echo "Starting GitLab import tests..."
try "$gi" import gitlab vyrondrosos git-issue-test-issues
start ; "$gi" list | try_grep 'An open issue on GitLab with a description and comments'
# Closed issues
start ; "$gi" list | try_grep -v 'A closed issue on GitLab without description'
start ; "$gi" list -a | try_grep 'A closed issue on GitLab without description'
# Description and comments
glissue=$("$gi" list | awk '/An open issue on GitLab with a description and comments/ {print $1}')
start ; "$gi" show "$glissue" | try_grep '^ *line 1$'
start ; "$gi" show "$glissue" | try_grep '^ *line 2$'
start ; "$gi" show "$glissue" | try_grep 'Line 3 with special characters "'\''<>|\$'
start ; "$gi" show -c "$glissue" | try_grep '^ *comment 2$'
start ; "$gi" show -c "$glissue" | try_grep '^ *comment 3$'
start ; "$gi" show -c "$glissue" | try_grep '^ *comment 4$'
start ; "$gi" show "$glissue" | try_grep '^GitLab issue: #[0-9]* at vyrondrosos/git-issue-test-issues$'
# Assignees and tags
glissue=$("$gi" list | awk '/An open issue on GitLab with assignees and tags/ {print $1}')
start ; "$gi" show "$glissue" | try_grep 'good first issue'
start ; "$gi" show "$glissue" | header_continuation | try_grep 'Assigned-to:.*'"$gluser"
# Milestone
try "$gi" list ver3
# Import should be idempotent
before=$(cd .issues ; git rev-parse --short HEAD)
try "$gi" import gitlab vyrondrosos git-issue-test-issues
after=$(cd .issues ; git rev-parse --short HEAD)
try test x"$before" = x"$after"
# Import repo belonging to group
try "$gi" import gitlab git-issue-test-group git-issue-subgroup-test/git-issue-group-test
start ; "$gi" list | try_grep 'Issue in group repo'
glissue2=$("$gi" list | awk '/Issue in group repo/ {print $1}')
start ; "$gi" show "$glissue2" | try_grep '^GitLab issue: #1 at git-issue-test-group/git-issue-subgroup-test/git-issue-group-test$'
# Export
# Create new repository to test issue exporting
echo "Trying to create GitLab repository..."
curl -H "$GL_CURL_AUTH" -s --header "Content-Type: application/json" --data '{"name": "git-issue-test-export-'"$($DATEBIN -Is | tr ':+' '--')"'", "visibility": "private"}' --output glrepo https://gitlab.com/api/v4/projects
if grep "git-issue-test-export" > /dev/null < glrepo ; then
echo "Starting export tests..."
glrepo=$(jq --raw-output '.path_with_namespace' < glrepo | tr '/' ' ')
glrepourl=$(jq --raw-output '._links.self' < glrepo)
gluser=$(jq --raw-output '.owner.username' < glrepo)
try "$gi" create -n "$issue" gitlab $glrepo
# Get the created issue
try "$gi" create -u "$(jq -r '.iid' .issues/create-body)" "$issue" gitlab $glrepo
rm -f .issues/create-body .issues/create-header
# modify and export
try "$gi" create -n "$issue2" gitlab $glrepo
try "$gi" new -c "gitlab $glrepo" -s "Issue exported directly"
"$gi" assign "$issue2" "$gluser" > /dev/null 2>&1
try "$gi" export gitlab $glrepo
"$gi" assign "$issue2" octocat > /dev/null 2>&1
try "$gi" export gitlab $glrepo
"$gi" assign -r "$issue2" octocat > /dev/null 2>&1
# test milestone creation
"$gi" new -s "gitlab milestone issue : %M" > /dev/null 2>&1
glissue3=$("$gi" list | awk '/gitlab milestone issue : %M/{print $1}')
"$gi" milestone "$glissue3" ver4 > /dev/null 2>&1
"$gi" duedate "$glissue3" week > /dev/null 2>&1
"$gi" timeestimate "$glissue3" 3hours > /dev/null 2>&1
try "$gi" create -e "$glissue3" gitlab $glrepo
start ; "$gi" show "$glissue3" | try_grep 'ver4'
# Try to create duplicate
ntry "$gi" create -e "$glissue3" gitlab $glrepo
try "$gi" exportall -a gitlab $glrepo
# Basic GitLab round-trip tests
echo "Starting GitHub round-trip test..."
cd ..
mkdir testdir4
cd testdir4
"$gi" init
try "$gi" import gitlab $glrepo
start ; "$gi" list | try_grep 'An open issue on GitLab with a description and comments'
# Closed issues
start ; "$gi" list | try_grep -v 'A closed issue on GitLab without description'
start ; "$gi" list -a | try_grep 'A closed issue on GitLab without description'
# Description and comments
rglissue=$("$gi" list | awk '/An open issue on GitLab with a description and comments/ {print $1}')
rglissue2=$("$gi" list | awk '/gitlab milestone issue/ {print $1}')
start ; "$gi" show "$rglissue" | try_grep '^ *line 1'
start ; "$gi" show "$rglissue" | try_grep '^ *line 2'
start ; "$gi" show "$rglissue" | try_grep 'Line 3 with special characters "'\''<>|\$'
start ; "$gi" show -c "$rglissue" | try_grep '^ *comment 2'
start ; "$gi" show -c "$rglissue" | try_grep '^ *comment 3'
start ; "$gi" show -c "$rglissue" | try_grep '^ *comment 4'
start ; "$gi" show "$rglissue" | try_grep '^GitLab issue: #[0-9]* at vyrondrosos/git-issue'
start ; "$gi" show "$rglissue2" | try_grep "^Due Date: $($DATEBIN --date=week --rfc-3339=date)"
start ; "$gi" show "$rglissue2" | try_grep '^Time Estimate: 03 hours'
start ; "$gi" show "$rglissue2" | try_grep '^Milestone: ver4'
# Assignees and tags
rglissue3=$("$gi" list | awk '/An open issue on GitLab with assignees and tags/ {print $1}')
start ; "$gi" show "$rglissue3" | try_grep 'good first issue'
start ; "$gi" show "$rglissue3" | header_continuation | try_grep 'Assigned-to:.*'"$gluser"
cd ../testdir
# delete repo
curl -H "$GL_CURL_AUTH" -s --request DELETE $glrepourl |
grep "Accepted" > /dev/null || printf "Couldn't delete repository.
You probably don't have delete permittions activated on the OAUTH token.\\nPlease delete %s manually." "$glrepo"
else
echo "Couldn't create test repository. Skipping export tests."
fi
fi
if ! [ -r "$TopDir/failure" ]; then
echo "All tests passed!"
exit 0
else
echo "Some test(s) failed: $(cat "$TopDir/failure")"
if [ -n "$TRAVIS_OS_NAME" ] ; then
echo 'Error output follows' 1>&2
cat "$TopDir/error.log" 1>&2
else
echo "Error output is in $TopDir/error.log"
fi
exit 1
fi