-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathissue-intake.sh
More file actions
executable file
·81 lines (68 loc) · 2.54 KB
/
issue-intake.sh
File metadata and controls
executable file
·81 lines (68 loc) · 2.54 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
81
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. "${ROOT_DIR}/github-intake/lib/intake-common.sh"
require_env GITHUB_EVENT_PATH
require_env GITHUB_REPOSITORY
require_env GITHUB_SERVER_URL
require_env GITHUB_API_URL
require_env GITLAB_BASE_URL
require_env GITLAB_PROJECT_PATH
require_env GITLAB_API_TOKEN
EVENT_JSON="$(python3 - "${GITHUB_EVENT_PATH}" <<'PY'
import json
import sys
event = json.load(open(sys.argv[1]))
issue = event["issue"]
payload = {
"number": issue["number"],
"title": issue["title"],
"body": issue.get("body") or "",
"html_url": issue["html_url"],
"author": issue["user"]["login"],
"state": issue["state"],
}
print(json.dumps(payload))
PY
)"
ISSUE_NUMBER="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["number"])' "${EVENT_JSON}")"
ISSUE_TITLE="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["title"])' "${EVENT_JSON}")"
ISSUE_BODY="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["body"])' "${EVENT_JSON}")"
ISSUE_URL="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["html_url"])' "${EVENT_JSON}")"
ISSUE_AUTHOR="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["author"])' "${EVENT_JSON}")"
ISSUE_STATE="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["state"])' "${EVENT_JSON}")"
MARKER="github-intake:issue:${GITHUB_REPOSITORY}#${ISSUE_NUMBER}"
LABELS="${GITLAB_INTAKE_LABEL:-github-intake,github-intake::issue}"
EXISTING="$(gitlab_find_issue_by_marker "${MARKER}")"
if [[ -n "${EXISTING}" ]]; then
GITLAB_ISSUE_URL="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["web_url"])' "${EXISTING}")"
echo "GitLab issue already exists: ${GITLAB_ISSUE_URL}"
else
DESCRIPTION="$(cat <<EOF
<!-- ${MARKER} -->
# GitHub Issue Intake
- Source issue: ${ISSUE_URL}
- Source repository: ${GITHUB_REPOSITORY}
- Source author: ${ISSUE_AUTHOR}
- Source state: ${ISSUE_STATE}
- Intake marker: \`${MARKER}\`
## GitHub Body
\`\`\`
${ISSUE_BODY}
\`\`\`
EOF
)"
CREATED="$(gitlab_create_issue "[GitHub Issue #${ISSUE_NUMBER}] ${ISSUE_TITLE}" "${DESCRIPTION}" "${LABELS}")"
GITLAB_ISSUE_URL="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["web_url"])' "${CREATED}")"
echo "Created GitLab issue: ${GITLAB_ISSUE_URL}"
fi
maybe_post_backlink_comment \
"${ISSUE_NUMBER}" \
"${MARKER}" \
"Tracked in GitLab: ${GITLAB_ISSUE_URL}\n\nMarker: \`${MARKER}\`"
cat <<EOF
issue_number=${ISSUE_NUMBER}
marker=${MARKER}
gitlab_issue_url=${GITLAB_ISSUE_URL}
backlink_mode=${GITHUB_BACKLINK_MODE:-none}
EOF