Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Default Token by GitHub #60

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions __test__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { join } from 'node:path'
import { debug } from '@actions/core'
import { context } from '@actions/github'
let octokit
const testTimeout = 20_000
const testTimeout = 30_000
jest.setTimeout(testTimeout)
beforeEach(() => {
for (const key of Object.keys(process.env)) {
Expand Down Expand Up @@ -62,11 +62,11 @@ describe('github', () => {
})
it('should-deleteReleaseAndTag', async function () {
await createRelease()
await delay(1000)
await delay(10000)
let searchedReleases = await getReleases(octokit, 'latest-*')
expect(searchedReleases).not.toBeUndefined()
expect(searchedReleases.length).toEqual(1)
await rmReleases(octokit, 'latest-*')
await rmReleases(octokit, 'latest-*', '^v0.0.*')
searchedReleases = await getReleases(octokit, 'latest-*')
expect(searchedReleases).not.toBeUndefined()
expect(searchedReleases.length).toEqual(0)
Expand Down Expand Up @@ -113,6 +113,6 @@ describe('github', () => {
).rejects.toThrowError()
})
it('print nothing found', async () => {
await rmReleases(octokit, 'idontexist')
await rmReleases(octokit, 'idontexist', '^v0.0.*')
})
})
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,23 @@ async function lsTags(octokit): Promise<Tag[]> {
debug(`Found ${tags.length} tags`)
return tags
}
async function deleteEmptyTag(octokit): Promise<void> {
async function deleteEmptyTag(octokit, skipPattern: string): Promise<void> {
const tags = await lsTags(octokit)
const regex = new RegExp(skipPattern, 'u')
await asyncForEach(tags, async tag => {
info(`Deleting empty tag with id ${tag.name}`)
await deleteTag(octokit, tag.name)
if (regex.test(tag.name)) {
info(`Skipping empty tag with id ${tag.name}`)
} else {
info(`Deleting empty tag with id ${tag.name}`)
await deleteTag(octokit, tag.name)
}
})
}

export async function rmReleases(
octokit,
releasePattern: string
releasePattern: string,
skipEmptyTag = '(?!.*)'
): Promise<void> {
const releases: Release[] = await getReleases(octokit, releasePattern)
const matches: number = releases.length
Expand All @@ -105,5 +111,5 @@ export async function rmReleases(
} else {
info('No release to delete.')
}
await deleteEmptyTag(octokit)
await deleteEmptyTag(octokit, skipEmptyTag)
}