Skip to content

Commit 592f727

Browse files
committed
fix: get coveralls data from correct directory
1 parent 51ebbc0 commit 592f727

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

helpers.sh

+34-7
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ ensure_jq_binary() {
425425

426426
git_log() {
427427
local format_value=$1
428-
local output
429428
echo "$(git --no-pager log -1 --pretty=format:"${format_value}" | "${jq_binary}" -Rs .)"
430429
}
431430

@@ -442,6 +441,14 @@ export_coveralls_data() {
442441
local service_pull_request=""
443442
local url="unknown"
444443

444+
# Change directory to the target project repository.
445+
# If input was read from stdin, presume we're in the right location already
446+
if is_file "${config_ston}"; then
447+
pushd "$(dirname ${config_ston})" > /dev/null
448+
else
449+
pushd "$(pwd)"
450+
fi
451+
445452
if ! grep -q "#coverage" "${config_ston}"; then
446453
return 0 # Coverage data not needed
447454
fi
@@ -498,18 +505,36 @@ export_coveralls_data() {
498505

499506
ensure_jq_binary # required for git_log
500507

508+
local author_email=""
509+
local author_name=""
510+
local committer_email=""
511+
local committer_name=""
512+
local commit_id=""
513+
local commit_message=""
514+
515+
author_email="$(git_log "%ae")"
516+
if [[ $? -ne 0 ]]; then
517+
print_error "Failed to parse Git log. Not a Git repository?"
518+
popd > /dev/null
519+
return 0
520+
fi
521+
author_name="$(git_log "%aN")"
522+
committer_email="$(git_log "%ce")"
523+
committer_name="$(git_log "%cN")"
524+
commit_id="$(git_log "%H")"
525+
commit_message="$(git_log "%s")"
501526
cat >"${SMALLTALK_CI_BUILD}/coveralls_build_data.json" <<EOL
502527
{
503528
${optional_values}
504529
"git": {
505530
"branch": "${branch_name}",
506531
"head": {
507-
"author_email": $(git_log "%ae"),
508-
"author_name": $(git_log "%aN"),
509-
"committer_email": $(git_log "%ce"),
510-
"committer_name": $(git_log "%cN"),
511-
"id": $(git_log "%H"),
512-
"message": $(git_log "%s")
532+
"author_email": "${author_email}",
533+
"author_name": "${author_name},
534+
"committer_email": "${committer_email}",
535+
"committer_name": "${committer_name}",
536+
"id": "${commit_id}",
537+
"message": "${commit_message}"
513538
},
514539
"remotes": [
515540
{
@@ -520,6 +545,8 @@ export_coveralls_data() {
520545
}
521546
}
522547
EOL
548+
549+
popd > /dev/null
523550
}
524551

525552
upload_coveralls_results() {

0 commit comments

Comments
 (0)