Skip to content

Commit

Permalink
post a comment for major version ups
Browse files Browse the repository at this point in the history
  • Loading branch information
kzkn committed Aug 26, 2024
1 parent 195ad4c commit ad2128f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
23 changes: 19 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ async function listUpdatedRubyGems(): Promise<AddedRubyGems[]> {
return parseDiff(pullRequest.toString())
}

function majorVersion(version: string): string {
return version.split('.')[0]
}

function isMajorVersionUp(gem: AddedRubyGems): boolean {
return (
!!gem.oldVersion &&
majorVersion(gem.oldVersion) !== majorVersion(gem.newVersion)
)
}

async function fetchRubyGemsDescription(gemname: string): Promise<Gem | null> {
const token = core.getInput('rubygemsToken')
const headers = {
Expand Down Expand Up @@ -153,13 +164,13 @@ function generateReport(
])
}

async function postComment(text: string): Promise<void> {
async function postComment(title: string, text: string): Promise<void> {
await replaceComment({
token: core.getInput('githubToken'),
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: github.context.issue.number,
body: `## Updated RubyGems ChangeLog URLs
body: `## ${title}
${text}
`
})
Expand Down Expand Up @@ -202,8 +213,17 @@ async function run(): Promise<void> {

core.debug('post report, start')
const versions = new Map(updatedRubyGems.map(gem => [gem.name, gem]))
const report = generateReport(changelogUrls, versions)
await postComment(report)
const majorVersionUps = changelogUrls.filter(({gem}) => {
const gemver = versions.get(gem.name)
return gemver && isMajorVersionUp(gemver)
})
if (majorVersionUps.length > 0) {
const majorVerUpReport = generateReport(majorVersionUps, versions)
await postComment(':warning: Major Version Up', majorVerUpReport)
}

const fullReport = generateReport(changelogUrls, versions)
await postComment('Updated RubyGems ChangeLog URLs', fullReport) // eslint-disable-line i18n-text/no-en
core.debug('post report, finish')
} catch (error: unknown) {
if (error instanceof Error) {
Expand Down

0 comments on commit ad2128f

Please sign in to comment.