Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 5494cd8

Browse files
authored
fixed issues #26 #32 #34
* Fixed #26 * Fixed #32 * Fixed #34 * update readme
1 parent 85f8ad8 commit 5494cd8

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

docs/README.md renamed to README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This action deletes older releases of given repo
55
Add following step to your workflow:
66

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

7575
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.*`
7676

77+
#### github_rest_api_url
78+
79+
| required | default |
80+
| -------- | ------------ |
81+
| false |api.github.com|
82+
83+
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
84+
7785
### Flow Chart (mermaid format)
7886

7987
```mermaid

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ inputs:
3131
delete_tag_pattern:
3232
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.
3333
required: false
34+
github_rest_api_url:
35+
description: the URL of the GitHub Rest API to be used. This might need to be different if you are a GitHub Enterprise user.
36+
required: false
37+
default: api.github.com
3438

3539
runs:
3640
using: "node16"

index.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ if (deletePatternStr) {
6565
console.log(`releases matching ${deletePatternStr} will be targeted`);
6666
deletePattern = new RegExp(deletePatternStr);
6767
}
68-
const commonOpts = {
69-
host: "api.github.com",
70-
port: 443,
71-
protocol: "https:",
72-
auth: `user:${GITHUB_TOKEN}`,
73-
headers: {
74-
"Content-Type": "application/json",
75-
"User-Agent": "node.js",
76-
},
77-
};
7868

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

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

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

90+
let gitHubRestApi = process.env.INPUT_GITHUB_REST_API_URL || "api.github.com";
91+
92+
const commonOpts = {
93+
host: gitHubRestApi,
94+
port: 443,
95+
protocol: "https:",
96+
auth: `user:${GITHUB_TOKEN}`,
97+
headers: {
98+
"Content-Type": "application/json",
99+
"User-Agent": "node.js",
100+
},
101+
};
100102

101103

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

124126
const activeMatchedReleases = data.filter((item) => {
125127
if (deletePrereleaseOnly) {
126-
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0 && item.prerelease;
128+
if (deletePatternStr) {
129+
return !item.draft && item.assets.length > 0 && item.prerelease && item.tag_name.match(deletePattern);
130+
} else {
131+
return !item.draft && item.assets.length > 0 && item.prerelease;
132+
}
127133
} else {
128-
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0;
134+
if (deletePatternStr) {
135+
return !item.draft && item.assets.length > 0 && item.tag_name.match(deletePattern);
136+
} else {
137+
return !item.draft && item.assets.length > 0;
138+
}
129139
}
130140
})
131141

142+
// const activeMatchedReleases = data.filter((item) => {
143+
// const shouldDelete = deletePrereleaseOnly && deletePatternStr;
144+
// const isDraft = item.draft;
145+
// const hasAssets = item.assets.length > 0;
146+
// const isPrerelease = item.prerelease;
147+
// const isTagMatching = deletePatternStr ? item.tag_name.match(deletePattern) : true;
148+
149+
// return !isDraft && hasAssets && (shouldDelete ? (isTagMatching && isPrerelease) : true);
150+
// });
151+
132152
if (activeMatchedReleases.length === 0) {
133153
console.log(`😕 no active releases found. exiting...`);
134154
return;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "delete-older-releases",
3-
"version": "0.2.1",
3+
"version": "0.3.2",
44
"main": "index.js",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)