- fix formatting

- 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
This commit is contained in:
Mike Penz
2023-11-05 10:05:00 +00:00
committed by GitHub
parent e86f2bbfce
commit 8afbd5a789
19 changed files with 1145 additions and 4267 deletions
@@ -1,12 +1,14 @@
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 || ''
@@ -14,6 +16,47 @@ 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))
@@ -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}}'
@@ -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 || ''
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
+8 -4
View File
@@ -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)
}
})
@@ -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 = {
@@ -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 = {