Skip to content
Open
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
8 changes: 5 additions & 3 deletions scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ uri="$(jq -r '.source.uri // ""' < "${payload}")"
private_token="$(jq -r '.source.private_token // ""' < "${payload}")"
no_ssl="$(jq -r '.source.no_ssl // ""' < "${payload}")"
version_sha="$(jq -r '.version.sha // ""' < "${payload}")"
version_project_id="$(jq -r '.version.project_id // ""' < "${payload}")"

if [[ "${uri}" == *"git@"* ]]; then
gitlab_host="$(echo "${uri}" | sed -rn 's/.*git@(.*):([0-9]*\/+)?(.*)\.git/\1/p')"
Expand Down Expand Up @@ -50,21 +51,22 @@ new_versions=''

for i in $(seq 0 $((num_mrs - 1))); do
mr="$(echo "${open_mrs}" | jq -r '.['"$i"']')"
mr_project_id="$(echo "${mr}" | jq -r '.source_project_id')"
mr_sha="$(echo "${mr}" | jq -r '.sha')"
if [ "${mr_sha}" != "null" ]; then
mr_updated_at="$(curl -s -H "private-token: ${private_token}" "${protocol}://${gitlab_host}/api/v4/projects/$(urlencode "${project_path}")/repository/commits/${mr_sha}" \
| jq '.committed_date|.[:19]|strptime("%Y-%m-%dT%H:%M:%S")|mktime')"
if [ "${mr_updated_at}" -gt "${version_updated_at}" ] || [ -z "${version_sha}" ]; then
new_versions="${new_versions},{\"sha\":\"${mr_sha}\"}"
new_versions="${new_versions},{\"sha\":\"${mr_sha}\",\"project_id\":\"${mr_project_id}\"}"
fi
fi
done

new_versions="${new_versions#','}" # remove trailing comma
new_versions="[${new_versions}]" # make JSON array

if [ "${new_versions}" == '[]' ] && ! [ -z "${version_sha}" ]; then
new_versions="[{\"sha\":\"${version_sha}\"}]"
if [ "${new_versions}" == '[]' ] && ! [ -z "${version_sha}" ] && ! [ -z "${version_project_id}" ]; then
new_versions="[{\"sha\":\"${version_sha}\",\"project_id\":\"${version_project_id}\"}]"
fi

jq -n "${new_versions}" >&3
24 changes: 23 additions & 1 deletion scripts/in
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ uri="$(jq -r '.source.uri // ""' < "${payload}")"
username="$(jq -r '.source.username // ""' < "${payload}")"
password="$(jq -r '.source.password // ""' < "${payload}")"
private_key="$(jq -r '.source.private_key // ""' < "${payload}")"
private_token="$(jq -r '.source.private_token // ""' < "${payload}")"
no_ssl="$(jq -r '.source.no_ssl // ""' < "${payload}")"
version="$(jq -r '.version // ""' < "${payload}")"
commit_sha="$(echo "${version}" | jq -r '.sha // ""')"
commit_project_id="$(echo "${version}" | jq -r '.project_id // ""')"

if [[ ! -z "${private_key}" ]]; then
gitlab_host="$(echo "${uri}" | sed -rn 's/.*git@(.*):([0-9]*\/+)?(.*)\.git/\1/p')"
Expand All @@ -49,7 +52,26 @@ else
echo "default login ${username} password ${password}" > "${HOME}/.netrc" # Save credentials for git push below
fi

git clone "${uri}" "${destination}"
if [[ "${uri}" == *"git@"* ]]; then
gitlab_host="$(echo "${uri}" | sed -rn 's/.*git@(.*):([0-9]*\/+)?(.*)\.git/\1/p')"
port="$(echo "${uri}" | sed -rn 's/.*git@(.*):([0-9]*\/+)?(.*)\.git/\2/p')"
port=${port///} # remove trailing slash
project_path="$(echo "${uri}" | sed -rn 's/.*git@(.*):([0-9]*\/+)?(.*)\.git/\3/p')"
protocol='https'
else
gitlab_host="$(echo "${uri}" | sed -rn 's/(https?):\/\/([^\/]*)\/(.*)\.git/\2/p')"
project_path="$(echo "${uri}" | sed -rn 's/(https?):\/\/([^\/]*)\/(.*)\.git/\3/p')"
protocol="$(echo "${uri}" | sed -rn 's/(https?):\/\/([^\/]*)\/(.*)\.git/\1/p')"
fi

if [ "${no_ssl}" == 'true' ]; then
protocol='http'
fi

ssh_project_uri="$(curl -s -H "private-token: ${private_token}" "${protocol}://${gitlab_host}/api/v4/projects/${commit_project_id}" \
| jq -r '.ssh_url_to_repo')"

git clone "${ssh_project_uri}" "${destination}"

cd "${destination}"

Expand Down
17 changes: 15 additions & 2 deletions scripts/out
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,27 @@ cd "${path_to_repo}"

commit_sha="$(git rev-parse HEAD)"

# Find project id of merge request
version_project_id=-1
open_mrs="$(curl -s -H "private-token: ${private_token}" "${protocol}://${gitlab_host}/api/v4/projects/$(urlencode "${project_path}")/merge_requests?state=opened&order_by=updated_at")"
num_mrs="$(echo "${open_mrs}" | jq 'length')"
for i in $(seq 0 $((num_mrs - 1))); do
mr="$(echo "${open_mrs}" | jq -r '.['"$i"']')"
mr_project_id="$(echo "${mr}" | jq -r '.source_project_id')"
mr_sha="$(echo "${mr}" | jq -r '.sha')"
if [ "${mr_sha}" == "${commit_sha}" ]; then
version_project_id="$mr_project_id"
fi
done

curl \
--request POST \
--header "PRIVATE-TOKEN: ${private_token}" \
--header 'Content-Type: application/json' \
--data "{\"state\":\"${new_status}\",\"name\":\"${build_label}\",\"target_url\":\"${target_url}\"}" \
"${protocol}://${gitlab_host}/api/v4/projects/$(urlencode "${project_path}")/statuses/${commit_sha}"
"${protocol}://${gitlab_host}/api/v4/projects/${version_project_id}/statuses/${commit_sha}"

version="{\"sha\":\"${commit_sha}\"}"
version="{\"sha\":\"${commit_sha}\",\"project_id\":\"${version_project_id}\"}"

jq -n "{
version: ${version},
Expand Down