Jimmy Berry 944a7720f7 dist/ci/obs-deploy: replace osc request list with osc api call.
Even after trying to workaround requests sourced from target package
(ex. Factory -> Leap) by using -U the query still behaves incorrectly
since both -U and -M do not return request created by user as documentation
suggests, but rather those who are last user in state. This works as
expected directly after a request is created, but not once another user
modifies it.

At this point just avoid the mess entirely and issue query for exactly
what is desired which avoids user altogether.
2018-01-25 09:56:10 -06:00

46 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
osc-init
osc checkout "$OBS_PACKAGE"
cd "$OBS_PACKAGE"
rm *.obscpio
osc service disabledrun
# ensure _servicedata ends with a newline
tail -n1 _servicedata | read -r _ || echo >> _servicedata
osc addremove
# Always produced modified files, but only want to bother if new source.
if osc status | grep _servicedata ; then
echo "new revision found, committing..."
osc commit -m "$(grep -oP 'version: \K.*' *.obsinfo)"
else
echo "new revision not found, reverting local changes..."
osc revert .
fi
# Create submit request if none currently exists.
OBS_TARGET_PROJECT="$(osc info | grep -oP "Link info:.*?project \K[^\s,]+")"
OBS_TARGET_PACKAGE="$(osc info | grep -oP "Link info:.*?, package \K[^\s,]+")"
echo "checking for existing requests to $OBS_TARGET_PROJECT/$OBS_TARGET_PACKAGE..."
# `osc request list` is wholly inadequate for the task. :(
if osc api "/search/request?match=(state/@name='declined'+or+state/@name='new'+or+state/@name='review')+and+action/target/@project='$OBS_TARGET_PROJECT'+and+action/target/@package='$OBS_TARGET_PACKAGE'" |
grep '<collection matches="0">' ; then
osc service wait
# Only bother making a request if there is a diff (always 6 lines since
# binary source tarball dates changed after local run).
if [ "$(osc sr --diff | tee temp.diff | wc -l)" -gt 6 ] ; then
echo "-> creating request"
cat temp.diff
rm temp.diff
osc sr --yes -m "automatic update"
else
echo "-> no difference (likely cron job)"
fi
else
echo "-> existing request"
fi