Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ jobs:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Checkout 🛎️
uses: actions/checkout@v5

- name: Install pnpm
uses: pnpm/action-setup@v2.4.1
Expand All @@ -34,6 +33,10 @@ jobs:
run: |
./install_bins.sh

- name: Checkout BCR submodule
run: |
git submodule update --init -- data/bazel-central-registry

- name: Checkout latest commit of BCR submodule
if: ${{ !inputs.bcrCommitHash }}
working-directory: data/bazel-central-registry
Expand All @@ -46,26 +49,6 @@ jobs:
run: |
git checkout ${{ inputs.bcrCommitHash }}

- name: Find latest successful run of another workflow
id: find-run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
run_id=$(gh run list \
--workflow "fetch_repo_metadata.yml" \
--branch main \
--json databaseId,status,conclusion \
--jq 'map(select(.status=="completed" and .conclusion=="success")) | first | .databaseId')
echo "run_id=$run_id" >> $GITHUB_OUTPUT

- name: Download and extract artifact
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run download ${{ steps.find-run.outputs.run_id }} \
--name github_metadata \
--dir data/github_metadata

- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
run: |
pnpm install --frozen-lockfile
Expand Down
29 changes: 6 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ jobs:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Checkout 🛎️
uses: actions/checkout@v5

- name: Install pnpm
uses: pnpm/action-setup@v2.4.1
Expand All @@ -30,6 +29,10 @@ jobs:
- name: Check prettier formatting
run: pnpm prettier-check

- name: Checkout BCR submodule
run: |
git submodule update --init -- data/bazel-central-registry

- name: Checkout latest commit of BCR submodule
if: ${{ !inputs.bcrCommitHash }}
working-directory: data/bazel-central-registry
Expand All @@ -42,26 +45,6 @@ jobs:
run: |
git checkout ${{ inputs.bcrCommitHash }}

- name: Find latest successful run of another workflow
id: find-run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
run_id=$(gh run list \
--workflow "fetch_repo_metadata.yml" \
--branch main \
--json databaseId,status,conclusion \
--jq 'map(select(.status=="completed" and .conclusion=="success")) | first | .databaseId')
echo "run_id=$run_id" >> $GITHUB_OUTPUT

- name: Download and extract artifact
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run download ${{ steps.find-run.outputs.run_id }} \
--name github_metadata \
--dir data/github_metadata

- name: Build 🔧 # Outputs the result to the 'build' folder.
run: pnpm run build
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ yarn-error.log*
.netlify

/bazel-*
/data/github_metadata/*.json
52 changes: 0 additions & 52 deletions data/githubMetadata.ts

This file was deleted.

2 changes: 0 additions & 2 deletions data/github_metadata/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions data/moduleStaticProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ModuleInfo,
reverseDependencies,
} from './utils'
import { getGithubRepositoryMetadata } from './githubMetadata'

export interface VersionInfo {
version: string
Expand Down Expand Up @@ -45,19 +44,12 @@ export const getStaticPropsModulePage = async (
const latestVersion = versions[0]
const selectedVersion = version || latestVersion

// Get GitHub metadata from static JSON files
const githubMetadata = await getGithubRepositoryMetadata(module)
if (!githubMetadata) {
console.warn(`No GitHub metadata found for module ${module}`)
}

return {
props: {
metadata,
versionInfos,
selectedVersion,
reverseDependencies: await reverseDependencies(module),
githubMetadata,
},
}
}
Expand Down
70 changes: 62 additions & 8 deletions pages/modules/[module].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
getStaticPropsModulePage,
VersionInfo,
} from '../../data/moduleStaticProps'
import { GithubRepositoryMetadata } from '../../data/githubMetadata'
import { formatDistance, parseISO } from 'date-fns'
import { faGlobe, faScaleBalanced } from '@fortawesome/free-solid-svg-icons'

Expand All @@ -26,7 +25,6 @@ interface ModulePageProps {
versionInfos: VersionInfo[]
selectedVersion: string
reverseDependencies: string[]
githubMetadata: GithubRepositoryMetadata | null
}

const GITHUB_API_USER_AGENT = 'Bazel Central Registry UI'
Expand All @@ -42,7 +40,6 @@ const ModulePage: NextPage<ModulePageProps> = ({
versionInfos,
selectedVersion,
reverseDependencies,
githubMetadata,
}) => {
const router = useRouter()
const { module } = router.query
Expand All @@ -64,11 +61,12 @@ const ModulePage: NextPage<ModulePageProps> = ({
selectedVersion
)

// Use GitHub metadata from static build-time data instead of client-side hook
const repoDescription = githubMetadata?.description || undefined
const repoLicense = githubMetadata?.license || undefined
const repoTopics = githubMetadata?.topics || undefined
const repoStargazers = githubMetadata?.stargazers || undefined
const {
description: repoDescription,
license: repoLicense,
topics: repoTopics,
stargazers: repoStargazers,
} = useGithubMetadata(firstGithubRepository)

const isQualifiedForShowAllVersions =
versionInfos.length > NUM_VERSIONS_ON_PAGE_LOAD
Expand Down Expand Up @@ -623,4 +621,60 @@ const useDetectReleaseFormatViaGithubApi = (
return releaseTagFormat
}

const useGithubMetadata = (metadataRepository: string | undefined) => {
const githubOwnerAndRepo = metadataRepository?.replace('github:', '')
const [description, setDescription] = useState<string | undefined>(undefined)
const [license, setLicense] = useState<
{ spdx_id: string; name: string; url: string } | undefined
>()
const [topics, setTopics] = useState<string[]>([])
const [stargazers, setStargazers] = useState<number | undefined>(undefined)

useEffect(() => {
const fetchRepoDescription = async () => {
if (!githubOwnerAndRepo) {
return
}

try {
const response = await fetch(
`https://api.github.com/repos/${githubOwnerAndRepo}`,
{
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
'User-Agent': GITHUB_API_USER_AGENT,
'X-GitHub-Api-Version': GITHUB_API_VERSION,
},
}
)

if (response.ok) {
const repoData = await response.json()
setStargazers(repoData.stargazers_count)
setDescription(repoData.description)
if (repoData.license) {
setLicense(repoData.license)
}
Comment on lines +656 to +658

Choose a reason for hiding this comment

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

high

The license object from the GitHub API response contains a url property that points to another API endpoint, not a human-readable license page. Assigning repoData.license directly to the state will cause the UI to render a link to this API endpoint, which is not the intended behavior. You should manually construct the license object for the state, creating a URL that points to a public license repository like opensource.org. It is also good practice to verify that repoData.license.spdx_id exists before using it to construct the URL.

Suggested change
if (repoData.license) {
setLicense(repoData.license)
}
if (repoData.license && repoData.license.spdx_id) {
setLicense({
name: repoData.license.name,
spdx_id: repoData.license.spdx_id,
url: `https://opensource.org/licenses/${repoData.license.spdx_id}`,
});
}


if (Array.isArray(repoData.topics)) {
setTopics(repoData.topics)
}
}
} catch (error) {
console.error('Failed to fetch repository description:', error)
}
}

fetchRepoDescription()
}, [githubOwnerAndRepo])

return {
description,
license,
topics,
stargazers,
}
}

export default ModulePage