Skip to content

Commit

Permalink
Use authenticated user for manging packages
Browse files Browse the repository at this point in the history
  • Loading branch information
d22 committed Nov 17, 2021
1 parent 3330ac4 commit 10dbf66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ 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
23 changes: 4 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ 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
const versionsToKeep = core.getInput('versions-to-keep');


try {
const octokit = new Octokit({
auth: accessToken
});

console.info('package-name:', packageName);
console.info('versions-to-keep:', versionsToKeep)

console.info("find versions to delete");
const versionsToDelete = findVersionsToDelete(octokit)
.catch(e => {
Expand All @@ -34,14 +30,9 @@ try {


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

const data = response.data;
Expand All @@ -58,16 +49,10 @@ async function findVersionsToDelete(octokit) {


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

0 comments on commit 10dbf66

Please sign in to comment.