Skip to content

introduced change that fixes issue #91#128

Open
jjijon7000 wants to merge 1 commit into
devfrom
issue-91-populate-version
Open

introduced change that fixes issue #91#128
jjijon7000 wants to merge 1 commit into
devfrom
issue-91-populate-version

Conversation

@jjijon7000

Copy link
Copy Markdown

Summary

This PR automates population of the version field in generated code.json files so users no longer need to enter it manually.

What Changed

  • Added logic to fetch the latest release from the GitHub REST API using GET /repos/{owner}/{repo}/releases/latest.
  • Parsed the release response to extract a usable version string from the tag name.
  • Wired the fetched version into the generated code.json metadata.
  • Added fallback handling so the action keeps working if the API request fails, rate limits are hit, the repository has no release, or no usable version is returned.
  • Updated the test mocks and unit tests to cover both the success path and the fallback path.

Validation

  • Ran focused unit tests for the touched areas:
    • src/__tests__/unit/helper.test.ts
    • src/__tests__/unit/main.test.ts

Notes

  • If the release version cannot be fetched, the action falls back to the existing code.json version value so manual input remains available as a safe backup.

@jjijon7000 jjijon7000 added the enhancement New feature or request label Jul 14, 2026

@natalialuzuriaga natalialuzuriaga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before approving, just wanted to ask about the current implementation choices and see whether other alternate approaches could be better suited. I also defer to Sachin though since he wrote the existing code!

Comment thread src/helper.ts
Comment on lines +16 to +18
async function calculateMetaData(
existingCodeJSON?: CodeJSON | null,
): Promise<Partial<CodeJSON>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a big change to add existingCodeJSON as an argument to this core function and wondering if this is necessary to do? Based on reviewing the code, I see an existing pattern where merging content between existingCodeJSON and partialCodeJSON occurs in the main.ts (I'll point to it in the next comment). Also, the getBasicInfo() function does very similar functionality as getVersion()where it calls the GitHub API to fetch data about the repo and eventually merges this data with existingCodeJSON

Just wanted to flag and see if we can follow patterns laid out in the existing code for consistency and evaluate whether adding the existingCodeJSON argument is truly necessary

Comment thread src/main.ts
Comment on lines +96 to 106
const partialCodeJSON = await helpers.calculateMetaData(existingCodeJSON);

// preserve existing feedback mechanisms if they exist, otherwise default to GitHub Issues
const feedbackMechanism =
existingCodeJSON?.feedbackMechanism ||
`${partialCodeJSON.repositoryURL}/issues`;

// preserve existing SBOM link if they exist, otherwise default to GitHub SBOM link
const SBOM =
existingCodeJSON?.SBOM ||
`${partialCodeJSON.repositoryURL}/network/dependencies`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below shows the pattern of how we merge existingCodeJSON with partialCodeJSON. We can do the same here with version?

Comment thread src/helper.ts
Comment on lines 91 to 96
async function getBasicInfo(): Promise<BasicRepoInfo> {
try {
const [repoData, languagesData] = await Promise.all([
octokit.rest.repos.get({ owner, repo }),
octokit.rest.repos.listLanguages({ owner, repo }),
]);

@natalialuzuriaga natalialuzuriaga Jul 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offering another implementation approach: we could instead add the version functionality to getBasicInfo() since it also uses octokit. Does octokit.rest.repos.get({owner, repo}) receive data on the repo's release tags? If so, could be worth just adding version into this function. If not, then a separate function makes sense

@natalialuzuriaga

natalialuzuriaga commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Last thing: as specified in our OSPO Gen AI Policy that was just shipped, please fill out this information about Gen AI usage and add this to your PR description:

AI Usage

  • Generated AI was used in this contribution

If checked, please provide an explanation on how AI was used in the development of this pull request:

  • Description: Include a high level description of Gen AI utilization
  • Type of assistance:
     - [ ] Code generation
     - [ ] Documentation
     - [ ] Debugging
     - [ ] Testing
     - [ ] Refactoring
     - [ ] Other:
  • Scope of usage: Which files, functions, or sections were AI-assisted
  • AI System used:
     - [ ] ChatGPT
     - [ ] Claude
     - [ ] Gemini
     - [ ] GitHub Copilot
  • Level of modification:
     - [ ] As-is
     - [ ] Modified
     - [ ] Used as inspiration
  • Prompts used: Please list or explain prompts that were used to develop this contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants