diff --git a/docs/README.md b/README.md similarity index 87% rename from docs/README.md rename to README.md index 4540177..bfed912 100644 --- a/docs/README.md +++ b/README.md @@ -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: / # defaults to current repo keep_latest: 3 @@ -74,6 +74,14 @@ Repo name in the format of `/`. 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 diff --git a/action.yml b/action.yml index 8d18e83..ddcdb30 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/index.js b/index.js index b158ea1..9da6792 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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) { @@ -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; diff --git a/package.json b/package.json index 64a56a7..30901a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "delete-older-releases", - "version": "0.2.1", + "version": "0.3.2", "main": "index.js", "repository": { "type": "git",