Skip to content

Commit

Permalink
support for user and organisations
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito authored and vlaurin committed Nov 3, 2021
1 parent ea2c49f commit ba58356
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ typings/

# TernJS port file
.tern-port

# idea project files
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ As a result, for this action to work, the token must be associated to a user who

### organization

**Required** Name of the organisation owning the container package.
Name of the organization owning the container package. (if empty, the packages of the authenticated user are considered)

### container

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ inputs:
required: true
organization:
description: 'Organisation to which the container belongs'
required: true
required: false
user:
description: 'User to which the container belongs'
required: false
container:
description: 'Name of the container to prune'
required: true
Expand Down
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,27 @@ const listOrgContainerVersions = (octokit) => (organization, container) => (page
state: 'active',
});

const listUserContainerVersions = (octokit) => (container) => (pageSize, page = 1) => octokit.rest.packages.getAllPackageVersionsForPackageOwnedByAuthenticatedUser({
package_type: 'container',
package_name: container,
page,
per_page: pageSize,
state: 'active',
});

const deleteOrgContainerVersion = (octokit) => (organization, container) => (version) => octokit.rest.packages.deletePackageVersionForOrg({
package_type: 'container',
org: organization,
package_name: container,
package_version_id: version.id,
});

const deleteUserContainerVersion = (octokit) => (container) => (version) => octokit.rest.packages.deletePackageVersionForAuthenticatedUser({
package_type: 'container',
package_name: container,
package_version_id: version.id,
});

const dryRunDelete = (version) => new Promise((resolve) => {
console.log(`Dry-run pruning of: `, versionSummary(version));
resolve();
Expand Down Expand Up @@ -91,9 +105,16 @@ const run = async () => {

const octokit = github.getOctokit(token);

const listVersions = listOrgContainerVersions(octokit)(organization, container);
let listVersions
let pruneVersion
if (organization.length !== 0) {
listVersions = listOrgContainerVersions(octokit)(organization, container);
pruneVersion = dryRun ? dryRunDelete : deleteOrgContainerVersion(octokit)(organization, container);
} else {
listVersions = listUserContainerVersions(octokit)(container);
pruneVersion = dryRun ? dryRunDelete : deleteUserContainerVersion(octokit)(container);
}
const filterVersion = versionFilter({olderThan, untagged, tagRegex});
const pruneVersion = dryRun ? dryRunDelete : deleteOrgContainerVersion(octokit)(organization, container);

const pruningList = await getPruningList(listVersions, filterVersion)(keepLast);

Expand Down

0 comments on commit ba58356

Please sign in to comment.