forked from martinthomson/i-d-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.mk
77 lines (71 loc) · 3.05 KB
/
issues.mk
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
GH_ISSUES := gh-pages
.PHONY: fetch-ghissues
fetch-ghissues:
-git fetch -q origin $(GH_ISSUES):$(GH_ISSUES)
ifneq (,$(GH_TOKEN))
GITHUB_OAUTH := -H "Authorization: token $(GH_TOKEN)"
endif
## Store a copy of any github issues
.PHONY: issues
issues: issues.json pulls.json
issues.json pulls.json: fetch-ghissues $(drafts_source)
@skip=$(DISABLE_ISSUE_FETCH); \
if [ $(CI) = true -a "$$skip" != true ]; then \
if [ -f $@ ] && [ "$(call last_modified,$@)" -gt "$(call last_commit,$(GH_ISSUES),$@)" ]; then \
skip=true; \
fi; \
if [ -n "$$(git rev-list -n 1 --since=$$(($$(date '+%s')-28800)) $(GH_ISSUES) -- $@)" ]; then \
skip=true; echo 'Skipping update of $@ (most recent update was in the last 8 hours)'; \
fi; \
fi; \
if [ "$$skip" = true ]; then \
git show $(GH_ISSUES):$@ > $@; exit; \
fi; \
echo '[' > $@; \
url=https://api.github.com/repos/$(GITHUB_REPO_FULL)/$(basename $(notdir $@))?state=all; \
tmp=$$(mktemp /tmp/$(basename $(notdir $@)).XXXXXX); trap 'rm -f $$tmp' EXIT; \
while [ -n "$$url" ]; do \
echo "Fetching $(basename $(notdir $@)) from $$url"; \
$(curl) $(GITHUB_OAUTH) $$url -D $$tmp | sed -e '1s/^ *\[//;$$s/\] *$$//' >> $@; \
if ! head -1 $$tmp | grep -q ' 200 OK'; then \
echo "Error loading $$url:"; cat $$tmp; exit 1; \
fi; \
url=$$(sed -e 's/^Link:.*<\([^>]*\)>;[^,]*rel="next".*/\1/;t;d' $$tmp); \
[ -n "$$url" ] && echo , >> $@; \
done; \
echo ']' >> $@
GHISSUES_ROOT := /tmp/ghissues$(shell echo $$$$)
$(GHISSUES_ROOT): fetch-ghissues
@git show-ref refs/heads/$(GH_ISSUES) >/dev/null 2>&1 || \
(git show-ref refs/remotes/origin/$(GH_ISSUES) >/dev/null 2>&1 && \
git branch -t $(GH_ISSUES) origin/$(GH_ISSUES)) || \
! echo 'Error: No $(GH_ISSUES) branch, run `make -f $(LIBDIR)/setup.mk setup-issues` to initialize it.'
git clone -q -b $(GH_ISSUES) . $@
$(GHISSUES_ROOT)/%.json: %.json $(GHISSUES_ROOT)
cp -f $< $@
## Commit and push the changes to $(GH_ISSUES)
.PHONY: ghissues gh-issues
gh-issues: ghissues
ghissues: $(GHISSUES_ROOT)/issues.json $(GHISSUES_ROOT)/pulls.json
cp -f $(LIBDIR)/template/issues.html $(LIBDIR)/template/issues.js $(GHISSUES_ROOT)
git -C $(GHISSUES_ROOT) add -f issues.json pulls.json issues.html issues.js
if test `git -C $(GHISSUES_ROOT) status --porcelain issues.json issues.js issues.html | wc -l` -gt 0; then \
git -C $(GHISSUES_ROOT) $(CI_AUTHOR) commit -m "Script updating issues at $(shell date -u +%FT%TZ). [ci skip]"; fi
ifeq (true,$(PUSH_GHPAGES))
ifneq (,$(if $(CI_HAS_WRITE_KEY),1,$(if $(GH_TOKEN),,1)))
git -C $(GHISSUES_ROOT) push https://github.com/$(CI_REPO_FULL) $(GH_ISSUES)
else
@echo git -C $(GHISSUES_ROOT) push -q https://github.com/$(CI_REPO_FULL) $(GH_ISSUES)
@git -C $(GHISSUES_ROOT) push -q https://$(GH_TOKEN)@github.com/$(CI_REPO_FULL) $(GH_ISSUES) >/dev/null 2>&1
endif
else
git -C $(GHISSUES_ROOT) push origin $(GH_ISSUES)
endif # PUSH_GHPAGES
-rm -rf $(GHISSUES_ROOT)
## Save issues.json to the CI_ARTIFACTS directory
ifneq (,$(CI_ARTIFACTS))
ifeq (true,$(SAVE_ISSUES_ARTIFACT))
.PHONY: artifacts
artifacts: issues.json pulls.json
endif
endif