Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion github/lib
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function bl_hub_add_issue_comment(){
function bl_hub_comment_or_create_issue(){
local title="${1}"
local message="${2}"
local label="${3:-}"
local label_param=""
local issue_number
local issue_url
local action
Expand All @@ -96,10 +98,20 @@ function bl_hub_comment_or_create_issue(){

if [[ -z "${issue_number}" ]]; then
action="created"
if [[ -n "${label}" ]]; then
label_param="-l ${label}"
fi

# issue doesn't exist create it

# The following prevents a shellcheck warning about label_param
# getting split into multiple words. That is exactly what should
# happen as "-l" and "labelname" should be separate tokens for
# the hub command.
# shellcheck disable=SC2086
issue_url="$(hub issue create -m "${title}

${message}")"
${message}" ${label_param})"

# Example issue url: https://github.com/{owner}/{repo}/issues/{issue number}"
# To find the issue number, split on / and take the last field
Expand Down
17 changes: 16 additions & 1 deletion tests-for-this-repo/github.bats
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ EOF

@test "bl_hub_comment_or_create_issue creates issue when it doesnt exist" {
bl_hub_check(){ :; }
bl_hub_ssue_number_for_title(){ :; }
bl_hub_issue_number_for_title(){ :; }
bl_github_owner_repo(){ echo "owner/repo"; }
hub(){
if [[ "${2:-}" == "create" ]]; then
Expand Down Expand Up @@ -195,3 +195,18 @@ EOF
assert_output --partial "comment"
assert_output --partial "https://github.com/owner/repo/issues/1"
}

@test "bl_hub_comment_or_create_issue passes label to hub" {
bl_hub_check(){ :; }
bl_hub_issue_number_for_title(){ :; }
bl_github_owner_repo(){ echo "owner/repo"; }
hub(){
[[ "${5}" == "-l" ]] || bl_die "expected -l for specifying a label"
[[ "${6}" == "label" ]] || bl_die "expected 'label' as label name"
echo "https://github.com/owner/repo/issues/1"
}
run bl_hub_comment_or_create_issue title message label
assert_success
assert_output --partial "https://github.com/owner/repo/issues/1"
assert_output --partial "create"
}