Compare commits

..

No commits in common. "249b14c27e2d7ea0b07b57aaf1e9b2ac060dc68e" and "b190def36fab6bf62e3e69382f8da9783b44a121" have entirely different histories.

4 changed files with 9 additions and 44 deletions

View file

@ -1,4 +1,2 @@
# WoodpeckerPlugins
Simple plugins I created and use for Woodpecker CI. Check subdirectories for specific plugin READMEs.
*The code for all of these is probably awful to look at because functionality is a lot more important to me in single-file scripts than proper conventions are. Sorry!*

View file

@ -28,13 +28,12 @@ steps:
# optional retention settings, useful if old builds should be deleted automatically
retentionamount: 7 # amount of children that retentionbase is allowed to have before oldest ones are deleted on upload
retentionbase: Uploads # directory that the retentionamount applies to
retentionskiptrash: false # whether retention-based deletion should skip the Nextcloud trash, defaults to false
# misc optional settings
basedir: "." # local base directory for files, defaults to .
chunksize: # chunk size in bytes, defaults to 10485760, or 10 MiB
quiet: false # whether to reduce output, defaults to false
quiet: false # whether to reduce output
tags: # a set of tags to apply to uploaded files, tag is expected to already exist
- mytag
flatten: false # whether to flatten directories, causing all files to be placed directly in dest, defaults to false
flatten: false # whether to flatten directories, causing all files to be placed directly in dest
```

View file

@ -22,12 +22,11 @@ if (!destEnv)
const baseDir = process.env.PLUGIN_BASEDIR || ".";
const chunkSizeEnv = process.env.PLUGIN_CHUNKSIZE || 10 * 1024 * 1024;
const quiet = process.env.PLUGIN_QUIET == "true";
const quiet = process.env.PLUGIN_QUIET || false;
const tags = process.env.PLUGIN_TAGS || "";
const flatten = process.env.PLUGIN_FLATTEN == "true";
const flatten = process.env.PLUGIN_FLATTEN || false;
const retentionBase = process.env.PLUGIN_RETENTIONBASE || "";
const retentionAmount = process.env.PLUGIN_RETENTIONAMOUNT || 0;
const retentionSkipTrash = process.env.PLUGIN_RETENTIONSKIPTRASH == "true";
upload();
@ -53,9 +52,8 @@ async function upload() {
let dirs = data["d:multistatus"]["d:response"].slice(1);
// sort directories by last modified
dirs.sort((a, b) => new Date(a["d:propstat"]["d:prop"]["d:getlastmodified"]) - new Date(b["d:propstat"]["d:prop"]["d:getlastmodified"]));
while (dirs.length >= parseInt(retentionAmount)) {
let dir = serverEnv + dirs[0]["d:href"];
let dirName = dir.substring(retentionPath.length - retentionBase.length).replace(/\/$/, "");
while (dirs.length > parseInt(retentionAmount)) {
let dir = `${serverEnv}${dirs[0]["d:href"]}`;
await axios.request({
method: "delete",
url: dir,
@ -64,36 +62,7 @@ async function upload() {
password: tokenEnv
}
});
// if we skip the trash, we actually also have to delete the item from the trash
if (retentionSkipTrash) {
let trashResponse = await axios.request({
method: "propfind",
url: `${basePath}/trashbin/${userEnv}/trash`,
auth: {
username: userEnv,
password: tokenEnv
},
data: `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
<d:prop>
<nc:trashbin-original-location/>
</d:prop>
</d:propfind>`
});
let trashContent = JSON.parse(xml.toJson(trashResponse.data))["d:multistatus"]["d:response"];
let trashItem = trashContent.find(e => e["d:propstat"]["d:prop"]["nc:trashbin-original-location"] == dirName);
await axios.request({
method: "delete",
url: serverEnv + trashItem["d:href"],
auth: {
username: userEnv,
password: tokenEnv
}
});
}
console.log(`Deleted directory ${dirName} because retention amount of ${retentionAmount} was reached${retentionSkipTrash ? " (skipped trash)" : ""}`);
console.log(`Deleted directory ${dir.substring(retentionPath.length + 1)} because retention amount of ${retentionAmount} was reached`);
dirs.splice(0, 1);
}
}

View file

@ -2,9 +2,8 @@ export PLUGIN_SERVER=https://cloud.ellpeck.de
export PLUGIN_USER=EllBot
export PLUGIN_FILES=**/*.md
export PLUGIN_DEST=Uploads/$(date '+%M:%S')
export PLUGIN_RETENTIONBASE=Uploads
export PLUGIN_RETENTIONAMOUNT=3
export PLUGIN_RETENTIONSKIPTRASH=true
export PLUGIN_RETENTION_BASE=Uploads
export PLUGIN_RETENTION_AMOUNT=3
npm install
node run.js