Skip to content

Commit

Permalink
Merge pull request #20 from zarplata/feature-out-push
Browse files Browse the repository at this point in the history
Add ability to push sources in out
  • Loading branch information
idr0id committed Jan 31, 2019
2 parents f364c07 + 8d7437a commit 93e4d0e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,21 @@ commit on the branch.
All `params` and `source` configuration of the original resource will be
respected.

### `out`: Update build task status.
### `out`: Update the PR.

This updates the build status of the pull request commit.
Behavior depends on the value of parameter `action`, where is the values are:

#### Parameters
* `change-build-status`: Change the commit build status.

* Parameters except the `name` will be respected the [Bitbucket documentation](https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/).
* `name`: `Deprecated`. Parameter is deprecated and has been left only for backward compatibility.
* `repository`: `Optional`. The path of the source repository for pushing or changing build status.
* `action`: `Required`. For this behavior should be `change-build-status`.
* Parameters except the `name` will be respected the [Bitbucket documentation](https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/).
* `name`: `Deprecated`. Parameter is deprecated and has been left only for backward compatibility.
* `repository`: `Optional`. The path of the source repository for changing build status.

* `push`: Push the commit to pull request branch.

* `action`: `Required`. For this behavior should be `push`.
* `repository`: `Optional`. The path of the source repository for pushing.

## Troubleshooting

Expand Down
61 changes: 56 additions & 5 deletions assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ username=$(jq -r '.source.username // ""' < "${payload}")
password=$(jq -r '.source.password // ""' < "${payload}")
project=$(jq -r '.source.project // ""' < "${payload}")
repository=$(jq -r '.source.repository // ""' < "${payload}")
dir=$(jq -r '.params.repository // .source.dir // .source.repository // ""' < "${payload}")
path=$(jq -r '.params.repository // .source.dir // .source.repository // ""' < "${payload}")
params=$(jq -rc '.params' < "${payload}")
action=$(jq -rc '.action // ""' <<< "${params}")

cd "${dir}"

pr=$(cat pull-request-info)
path="$(realpath "${PWD}"/"${path}")/"
pr=$(cat "${path}pull-request-info")

eval_param() {
eval echo "$(jq -r "${1}" <<< "${params}")"
Expand Down Expand Up @@ -79,4 +79,55 @@ change_build_status() {
}' >&3
}

change_build_status
push() {
git=$(jq -r '.source.git // ""' < "${payload}")

git_payload=$(jq -nc \
--argjson git "${git}" \
--argjson pr "${pr}" \
--arg repository "${path}" '
{
source: (
$git * {
branch: $pr.feature_branch
}
),
params: {
repository: $repository
}
}
')

git_payload_out=$(/opt/git-resource/out "${1}" <<< "${git_payload}")

jq -n --argjson pr "${pr}" --argjson git "${git_payload_out}" \
'{
version: {
id: $pr.id|tostring,
branch: $pr.feature_branch,
commit: $git.version.ref
},
metadata: $git.metadata
}' >&3
}

case "${action}" in
# case for backward compatibility
"")
echo "warning: please setup the \`action\` parameter"
change_build_status
;;

"change-build-status")
change_build_status
;;

"push")
push "${@%/}"
;;

*)
echo "error: incorrect params.action (${action})"
exit 1
;;
esac

0 comments on commit 93e4d0e

Please sign in to comment.