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

Migrate GitHub PR Collector to npm lib #1132

Merged
merged 12 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,26 @@ jobs:
with:
node-version: 16.x

- name: Install dependencies
run: npm ci
- name: Build PR-Collector
run: |
cd pr-collector
npm ci
npm run build
npm run package

- name: Rebuild the dist/ directory
- name: Build Action
run: |
cd pr-collector

npm ci
npm run build
npm run package

- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
git diff -a
exit 1
fi
id: diff
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:

- name: Run NPM
run: |
cd pr-collector
npm run all

cd ..
npm run all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

lib
pr-collector/dist
4 changes: 3 additions & 1 deletion __tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ it('Configurations are merged correctly', async () => {
const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile)

console.log(mergedConfiguration)
expect(JSON.stringify(mergedConfiguration)).toEqual(`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`)
expect(JSON.stringify(mergedConfiguration)).toEqual(
`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`
)
})
80 changes: 43 additions & 37 deletions __tests__/releaseNotesBuilderPull.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {pullData} from '../src/releaseNotesBuilder'
import {Octokit} from '@octokit/rest'
import { buildChangelog } from '../src/transform'
import {buildChangelog} from '../src/transform'
import { pullData } from 'github-pr-collector'

jest.setTimeout(180000)

Expand All @@ -13,7 +13,7 @@ const octokit = new Octokit({
it('Should have empty changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))

const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
Expand All @@ -25,16 +25,16 @@ it('Should have empty changelog (tags)', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual('- no changes')
})

it('Should match generated changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
Expand All @@ -46,9 +46,10 @@ it('Should match generated changelog (tags)', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
}
const data = await pullData(octokit, options)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests

Expand All @@ -60,7 +61,8 @@ it('Should match generated changelog (tags)', async () => {

it('Should match generated changelog (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json'))
const data = await pullData(octokit, {

const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
Expand All @@ -72,9 +74,10 @@ it('Should match generated changelog (refs)', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
}
const data = await pullData(octokit, options)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests

Expand All @@ -94,7 +97,7 @@ nhoelzl

it('Should match generated changelog and replace all occurrences (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
Expand All @@ -106,9 +109,9 @@ it('Should match generated changelog and replace all occurrences (refs)', async
fetchReviews: false,
commitMode: false,
configuration
}, false, false)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests

Expand All @@ -130,7 +133,7 @@ nhoelzl

it('Should match ordered ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
Expand All @@ -142,16 +145,17 @@ it('Should match ordered ASC', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
}
const data = await pullData(octokit, options)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n22\n24\n25\n26\n28\n\n## 🐛 Fixes\n\n23\n\n`)
})

it('Should match ordered DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
Expand All @@ -163,16 +167,17 @@ it('Should match ordered DESC', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
}
const data = await pullData(octokit, options)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n28\n26\n25\n24\n22\n\n## 🐛 Fixes\n\n23\n\n`)
})

it('Should match ordered by title ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
Expand All @@ -184,9 +189,9 @@ it('Should match ordered by title ASC', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nEnhanced action logs\nImprove README\nImproved configuration failure handling\nImproved defaults if no configuration is provided\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
Expand All @@ -195,7 +200,7 @@ it('Should match ordered by title ASC', async () => {

it('Should match ordered by title DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
Expand All @@ -207,9 +212,10 @@ it('Should match ordered by title DESC', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
}
const data = await pullData(octokit, options)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\nImproved defaults if no configuration is provided\nImproved configuration failure handling\nImprove README\nEnhanced action logs\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
Expand All @@ -218,7 +224,7 @@ it('Should match ordered by title DESC', async () => {

it('Should ignore PRs not merged into develop branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
Expand All @@ -230,16 +236,16 @@ it('Should ignore PRs not merged into develop branch', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`150\n\n`)
})

it('Should ignore PRs not merged into main branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
const data = await pullData(octokit, {
const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
Expand All @@ -251,9 +257,9 @@ it('Should ignore PRs not merged into main branch', async () => {
fetchReviews: false,
commitMode: false,
configuration
}, false, false)

const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`153\n\n`)
})
14 changes: 4 additions & 10 deletions __tests__/tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TagInfo, sortTags, filterTags} from '../src/tags'
import { TagInfo, filterTags, sortTags } from "github-pr-collector/lib/tags"

jest.setTimeout(180000)

Expand All @@ -23,9 +23,7 @@ it('Should order tags correctly using semver', async () => {
})
.join(',')

expect(sorted).toStrictEqual(
`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`
)
expect(sorted).toStrictEqual(`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`)
})

it('Should order tags correctly using semver', async () => {
Expand Down Expand Up @@ -54,9 +52,7 @@ it('Should order tags correctly using semver', async () => {
})
.join(',')

expect(sorted).toStrictEqual(
`1000.0.0,100.0.0,20.0.2,10.1.0,10.1.0-2,10.0.0,2.0.0,1.0.0,1.0.0-a01,0.1.0,0.1.0-b01,0.0.1,0.0.1-rc01`
)
expect(sorted).toStrictEqual(`1000.0.0,100.0.0,20.0.2,10.1.0,10.1.0-2,10.0.0,2.0.0,1.0.0,1.0.0-a01,0.1.0,0.1.0-b01,0.0.1,0.0.1-rc01`)
})

it('Should order tags alphabetical', async () => {
Expand Down Expand Up @@ -85,9 +81,7 @@ it('Should order tags alphabetical', async () => {
})
.join(',')

expect(sorted).toStrictEqual(
`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`
)
expect(sorted).toStrictEqual(`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`)
})

it('Should filter tags correctly using the regex', async () => {
Expand Down