Skip to content

Commit

Permalink
- fix formatting
Browse files Browse the repository at this point in the history
- apply some smaller fixes
- enable cache for 1 gitea test (no need to use API)
- do not cache and export token in cache
- speed up main.test.ts
  • Loading branch information
mikepenz authored Nov 5, 2023
1 parent e86f2bb commit 8afbd5a
Show file tree
Hide file tree
Showing 19 changed files with 1,145 additions and 4,267 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'
import {GiteaRepository} from '../src/repositories/GiteaRepository'
import {mergeConfiguration, resolveConfiguration} from '../../src/utils'
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder'
import {GiteaRepository} from '../../src/repositories/GiteaRepository'

jest.setTimeout(180000)

/**
* Before starting testing, you should manually clone the repository
* cd /tmp && git clone https://gitea.com/jolheiser/sip
* cd /tmp && git clone https://gitea.com/mikepenz/sip
*
* (Forked from: https://gitea.com/jolheiser/sip)
*/

const token = process.env.GITEA_TOKEN || ''
const workingDirectory = '/tmp/sip/'
const owner = 'jolheiser'
const repo = 'sip'
const configurationFile = 'configs/configuration_gitea.json'

it('[Gitea] Verify reviewers who approved are fetched and also release information', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))

const giteaRepository = new GiteaRepository(token, undefined, workingDirectory)
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
giteaRepository, // token
workingDirectory, // repoPath
owner, // user
repo, // repo
'v0.5.0', // fromTag
'master', // toTag
true, // includeOpen
false, // failOnError
false, // ignorePrePrelease
false, // enable to fetch via commits
true, // enable to fetch reviewers
true, // enable to fetch tag release information
false, // enable to fetch reviews
false, // enable commitMode
false, // enable exportCache
false, // enable exportOnly
null, // path to the cache
configuration // configuration
)

const changeLog = await releaseNotesBuilder.build()
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 📦 Uncategorized
- Add attachment removal and change message -- (#36) [merged] ---
- Change to vanity URL -- (#37) [merged] ---
4`
)
})

it('[Gitea] Should match generated changelog (unspecified fromTag)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile))

Expand Down Expand Up @@ -681,46 +724,6 @@ it('[Gitea] Verify custom categorisation of open PRs', async () => {
expect(changeLog).toStrictEqual(``)
})

it('[Gitea] Verify reviewers who approved are fetched and also release information', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))

const giteaRepository = new GiteaRepository(token, undefined, workingDirectory)
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
giteaRepository, // token
workingDirectory, // repoPath
owner, // user
repo, // repo
'v0.5.0', // fromTag
'master', // toTag
true, // includeOpen
false, // failOnError
false, // ignorePrePrelease
false, // enable to fetch via commits
true, // enable to fetch reviewers
true, // enable to fetch tag release information
false, // enable to fetch reviews
false, // enable commitMode
false, // enable exportCache
false, // enable exportOnly
null, // path to the cache
configuration // configuration
)

const changeLog = await releaseNotesBuilder.build()
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 📦 Uncategorized
- Add attachment removal and change message -- (#36) [merged] ---
- Change to vanity URL -- (#37) [merged] ---
4`
)
})

it('[Gitea] Fetch release information', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))
configuration.template = '#{{FROM_TAG}}-#{{FROM_TAG_DATE}}\n#{{TO_TAG}}-#{{TO_TAG_DATE}}\n#{{DAYS_SINCE}}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../src/utils'
import {buildChangelog} from '../src/transform'
import {pullData} from '../src/pr-collector/prCollector'
import {GiteaRepository} from '../src/repositories/GiteaRepository'
import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../../src/utils'
import {buildChangelog} from '../../src/transform'
import {pullData} from '../../src/pr-collector/prCollector'
import {GiteaRepository} from '../../src/repositories/GiteaRepository'

jest.setTimeout(180000)

// load octokit instance
const enablePullData = true // if false -> use cache for data
const enablePullData = false
/**
* if false -> use cache for data
* Use the below snippet to export the cache:
*
* writeCacheData({
* mergedPullRequests: data.mergedPullRequests,
* diffInfo: data.diffInfo,
* options
* }, 'caches/gitea_rcba_0.1.0-master_cache.json')
*/

/**
* Before starting testing, you should manually clone the repository
* cd /tmp && git clone https://gitea.com/jolheiser/sip
* cd /tmp && git clone https://gitea.com/mikepenz/sip
*
* (Forked from: https://gitea.com/jolheiser/sip)
*/

const token = process.env.GITEA_TOKEN || ''
Expand Down Expand Up @@ -40,7 +53,7 @@ it('[Gitea] Should have changelog (tags)', async () => {
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_0.0.2-0.0.3_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_0.5.0-master_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down Expand Up @@ -78,7 +91,7 @@ it('[Gitea] Should match generated changelog (tags)', async () => {
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_0.0.1-0.0.3_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_0.5.0-master_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down Expand Up @@ -117,7 +130,7 @@ it('[Gitea] Should match generated changelog (refs)', async () => {
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_5ec7a2-fa3788_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_3e49adf-894a64_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down Expand Up @@ -174,7 +187,7 @@ it('[Gitea] Should match generated changelog and replace all occurrences (refs)'
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_5ec7a2-fa3788_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_3e49adf-894a64_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down Expand Up @@ -236,7 +249,7 @@ it('[Gitea] Should match ordered ASC', async () => {
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_0.3.0-0.5.0_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_0.1.0-master_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down Expand Up @@ -293,7 +306,7 @@ it('[Gitea] Should match ordered DESC', async () => {
if (enablePullData) {
data = await pullData(giteaRepository, options)
} else {
data = checkExportedData(false, 'caches/rcba_0.3.0-0.5.0_cache.json')
data = checkExportedData(false, 'caches/gitea_rcba_0.1.0-master_cache.json')
}
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
Expand Down
12 changes: 8 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import * as fs from 'fs'
jest.setTimeout(180000)

test('missing values should result in failure', () => {
expect.assertions(1)

process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_OWNER'] = undefined
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: process.env
}
try {
cp.execSync(`node ${ip}`, options).toString()
fail('Should not succeed, because values miss')
} catch (error) {
console.log(`correctly failed due to: ${error}`)
} catch (error: any) {
expect(true).toBe(true)
}
})

Expand All @@ -27,6 +29,7 @@ test('complete input should succeed', () => {
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
process.env['INPUT_FROMTAG'] = 'v0.3.0'
process.env['INPUT_TOTAG'] = 'v0.5.0'
process.env['INPUT_CACHE'] = 'caches/rcba_0.3.0-0.5.0_cache.json'

const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
Expand All @@ -45,6 +48,7 @@ test('should write result to file', () => {
process.env['INPUT_FROMTAG'] = 'v0.3.0'
process.env['INPUT_TOTAG'] = 'v0.5.0'
process.env['INPUT_OUTPUTFILE'] = 'test.md'
process.env['INPUT_CACHE'] = 'caches/rcba_0.3.0-0.5.0_cache.json'

const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inputs:
cache:
description: 'Provide the cache of a previous run. Allows to re-use collected information multiple times to generate different release notes. Requires `exportCache` to be enabled for the previous run.'
platform:
description: 'use this action in github or gitea or other platform'
description: 'Defines the platform the action is run on. Available options: [`github`, `gitea`]. Defaults to `github`.'
default: "github"
outputs:
changelog:
Expand Down
Loading

0 comments on commit 8afbd5a

Please sign in to comment.