add additional check for empty pad

This commit is contained in:
Tim Schubert 2022-04-26 22:02:00 +02:00
parent 6423d1dc04
commit e1ecb7dc05
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA
2 changed files with 18 additions and 13 deletions

View file

@ -8,4 +8,4 @@ include:
file: 'lib/gitlab-ci.yml'
```
The including CI configuration has to provide a `CI_ACCESS_TOKEN` that can push to the repo.
The project including the CI configuration has to provide the variable `CI_ACCESS_TOKEN`. It must contain a project access token that can push to the repo.

27
update
View file

@ -8,20 +8,24 @@ update() {
curl --silent -k -o "${dst}" "${url}/export/txt"
status="$?"
if [ ${status} -ne 0 ]; then
echo "Failed to get pad at ${url}"
else
git -C "${gitdir}" add "${dst}"
changes=$(git -C "${gitdir}" diff --cached | wc -l)
if [ "$changes" -gt 0 ]; then
git -C "${gitdir}" commit -m "Updated: ${dst} from ${url}"
else
echo "Nothing changed for ${url}"
fi
echo "Failed to get pad at ${url}"
return
fi
git -C "${gitdir}" reset --hard HEAD
newlength="$(wc -l ${dst})"
if [ "$newlength" -lt 3 ]
then
return
fi
git -C "${gitdir}" add "${dst}"
changes=$(git -C "${gitdir}" diff --cached | wc -l)
if [ "$changes" -gt 0 ]; then
git -C "${gitdir}" commit -m "Updated: ${dst} from ${url}"
else
echo "Nothing changed for ${url}"
fi
}
if ! git rev-parse --is-inside-work-tree
@ -33,4 +37,5 @@ fi
while read -r pad
do
update "$pad"
git -C "${gitdir}" reset --hard HEAD
done