Skip to content

Commit

Permalink
Use specific user instead of authenticated user
Browse files Browse the repository at this point in the history
  • Loading branch information
d22 committed Nov 17, 2021
1 parent d83d342 commit 3330ac4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
package-name:
description: 'Name of the package to clean up'
required: true
username:
description: 'Username'
required: true
versions-to-keep:
description: 'How many versions should be kept, decending by creation date'
required: false
Expand Down
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { Octokit } = require("@octokit/rest");

const accessToken = core.getInput('access-token');
const packageName = core.getInput('package-name');
const username = core.getInput('username');
const versionsToKeep = core.getInput('versions-to-keep'); // *1


Expand All @@ -16,7 +17,10 @@ try {

console.info("find versions to delete");
const versionsToDelete = findVersionsToDelete(octokit)
.catch(e => console.error(e));
.catch(e => {
console.error(e);
throw new Error(e.message);
});

versionsToDelete.then(versions => {
console.info('going to delete the follwing versions: ', versions);
Expand All @@ -30,10 +34,16 @@ try {


async function findVersionsToDelete(octokit) {
let response = await octokit.rest.packages.getAllPackageVersionsForPackageOwnedByAuthenticatedUser({
// let response = await octokit.rest.packages.getAllPackageVersionsForPackageOwnedByAuthenticatedUser({
// package_type: 'container',
// package_name: packageName,
// });
let response = await octokit.rest.packages.getAllPackageVersionsForPackageOwnedByUser({
package_type: 'container',
package_name: packageName,
username: username
});

const data = response.data;
let versions = new Map();
data.forEach(version => {
Expand All @@ -49,9 +59,15 @@ async function findVersionsToDelete(octokit) {

async function deleteOldVersion(version, octokit) {
console.log("... deleting version ", version);
await octokit.rest.packages.deletePackageVersionForAuthenticatedUser({
// await octokit.rest.packages.deletePackageVersionForAuthenticatedUser({
// package_type: 'container',
// package_name: packageName,
// package_version_id: version
// });
await octokit.rest.packages.deletePackageVersionForUser({
package_type: 'container',
package_name: packageName,
username: username,
package_version_id: version
});
});
}

0 comments on commit 3330ac4

Please sign in to comment.