Skip to content

Commit

Permalink
fixed issues #26 #32 #34
Browse files Browse the repository at this point in the history
* Fixed #26
* Fixed #32
* Fixed #34
* update readme
  • Loading branch information
smallprogram committed Sep 29, 2023
1 parent 85f8ad8 commit 5494cd8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
10 changes: 9 additions & 1 deletion docs/README.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This action deletes older releases of given repo
Add following step to your workflow:

```yaml
- uses: dev-drprasad/delete-older-releases@v0.3.1
- uses: dev-drprasad/delete-older-releases@v0.3.2
with:
repo: <owner>/<repoName> # defaults to current repo
keep_latest: 3
Expand Down Expand Up @@ -74,6 +74,14 @@ Repo name in the format of `<owner>/<repoName>`. Defaults to the repo that execu

Specifies a release **tag** (not title) Regex string pattern to match. If not specified, then every release will be targeted. If specified, then every release containing the pattern will be targeted. Examples, `beta`, `^v2\..*-beta$`, `v3\.0.*`

#### github_rest_api_url

| required | default |
| -------- | ------------ |
| false |api.github.com|

Github rest api url, the default is "api.github.com". If you are an enterprise user, you can replace it with "{your-github-enterprise-url}/api/v3". Please refer to: https://docs.github.com/en/enterprise-cloud@latest/rest

### Flow Chart (mermaid format)

```mermaid
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
delete_tag_pattern:
description: part of the tag name. Example, if you want to delete 0.0.1-beta and 0.0.2-beta but not 0.0.1 then set this to just "beta". If not set then it will target all releases.
required: false
github_rest_api_url:
description: the URL of the GitHub Rest API to be used. This might need to be different if you are a GitHub Enterprise user.
required: false
default: api.github.com

runs:
using: "node16"
Expand Down
44 changes: 32 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ if (deletePatternStr) {
console.log(`releases matching ${deletePatternStr} will be targeted`);
deletePattern = new RegExp(deletePatternStr);
}
const commonOpts = {
host: "api.github.com",
port: 443,
protocol: "https:",
auth: `user:${GITHUB_TOKEN}`,
headers: {
"Content-Type": "application/json",
"User-Agent": "node.js",
},
};

let keepMinDownloadCount = Number(process.env.INPUT_KEEP_MIN_DOWNLOAD_COUNTS);

Expand All @@ -97,6 +87,18 @@ if (Number.isNaN(deleteExpiredData) || deleteExpiredData < 0) {

console.log("🌶 given `delete_expired_data` is ",deleteExpiredData);

let gitHubRestApi = process.env.INPUT_GITHUB_REST_API_URL || "api.github.com";

const commonOpts = {
host: gitHubRestApi,
port: 443,
protocol: "https:",
auth: `user:${GITHUB_TOKEN}`,
headers: {
"Content-Type": "application/json",
"User-Agent": "node.js",
},
};


async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpiredData) {
Expand All @@ -123,12 +125,30 @@ async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpir

const activeMatchedReleases = data.filter((item) => {
if (deletePrereleaseOnly) {
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0 && item.prerelease;
if (deletePatternStr) {
return !item.draft && item.assets.length > 0 && item.prerelease && item.tag_name.match(deletePattern);
} else {
return !item.draft && item.assets.length > 0 && item.prerelease;
}
} else {
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0;
if (deletePatternStr) {
return !item.draft && item.assets.length > 0 && item.tag_name.match(deletePattern);
} else {
return !item.draft && item.assets.length > 0;
}
}
})

// const activeMatchedReleases = data.filter((item) => {
// const shouldDelete = deletePrereleaseOnly && deletePatternStr;
// const isDraft = item.draft;
// const hasAssets = item.assets.length > 0;
// const isPrerelease = item.prerelease;
// const isTagMatching = deletePatternStr ? item.tag_name.match(deletePattern) : true;

// return !isDraft && hasAssets && (shouldDelete ? (isTagMatching && isPrerelease) : true);
// });

if (activeMatchedReleases.length === 0) {
console.log(`😕 no active releases found. exiting...`);
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delete-older-releases",
"version": "0.2.1",
"version": "0.3.2",
"main": "index.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit 5494cd8

Please sign in to comment.