Skip to content

Commit 78dcb95

Browse files
authored
Revert "feat: fetch repo metadata in staticProps" (bazel-contrib#183)
Reverts bazel-contrib#180 The change to submodule fetching with `@actions/checkout` doesn't get enough `--depth`
1 parent 03ec085 commit 78dcb95

File tree

7 files changed

+74
-117
lines changed

7 files changed

+74
-117
lines changed

.github/workflows/deploy.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ jobs:
2121
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v5
25-
with:
26-
submodules: true
24+
- name: Checkout 🛎️
25+
uses: actions/checkout@v5
2726

2827
- name: Install pnpm
2928
uses: pnpm/action-setup@v2.4.1
@@ -34,6 +33,10 @@ jobs:
3433
run: |
3534
./install_bins.sh
3635
36+
- name: Checkout BCR submodule
37+
run: |
38+
git submodule update --init -- data/bazel-central-registry
39+
3740
- name: Checkout latest commit of BCR submodule
3841
if: ${{ !inputs.bcrCommitHash }}
3942
working-directory: data/bazel-central-registry
@@ -46,26 +49,6 @@ jobs:
4649
run: |
4750
git checkout ${{ inputs.bcrCommitHash }}
4851
49-
- name: Find latest successful run of another workflow
50-
id: find-run
51-
env:
52-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
run: |
54-
run_id=$(gh run list \
55-
--workflow "fetch_repo_metadata.yml" \
56-
--branch main \
57-
--json databaseId,status,conclusion \
58-
--jq 'map(select(.status=="completed" and .conclusion=="success")) | first | .databaseId')
59-
echo "run_id=$run_id" >> $GITHUB_OUTPUT
60-
61-
- name: Download and extract artifact
62-
env:
63-
GH_TOKEN: ${{ github.token }}
64-
run: |
65-
gh run download ${{ steps.find-run.outputs.run_id }} \
66-
--name github_metadata \
67-
--dir data/github_metadata
68-
6952
- 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.
7053
run: |
7154
pnpm install --frozen-lockfile

.github/workflows/test.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ jobs:
1212
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v5
16-
with:
17-
submodules: true
15+
- name: Checkout 🛎️
16+
uses: actions/checkout@v5
1817

1918
- name: Install pnpm
2019
uses: pnpm/action-setup@v2.4.1
@@ -30,6 +29,10 @@ jobs:
3029
- name: Check prettier formatting
3130
run: pnpm prettier-check
3231

32+
- name: Checkout BCR submodule
33+
run: |
34+
git submodule update --init -- data/bazel-central-registry
35+
3336
- name: Checkout latest commit of BCR submodule
3437
if: ${{ !inputs.bcrCommitHash }}
3538
working-directory: data/bazel-central-registry
@@ -42,26 +45,6 @@ jobs:
4245
run: |
4346
git checkout ${{ inputs.bcrCommitHash }}
4447
45-
- name: Find latest successful run of another workflow
46-
id: find-run
47-
env:
48-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
run: |
50-
run_id=$(gh run list \
51-
--workflow "fetch_repo_metadata.yml" \
52-
--branch main \
53-
--json databaseId,status,conclusion \
54-
--jq 'map(select(.status=="completed" and .conclusion=="success")) | first | .databaseId')
55-
echo "run_id=$run_id" >> $GITHUB_OUTPUT
56-
57-
- name: Download and extract artifact
58-
env:
59-
GH_TOKEN: ${{ github.token }}
60-
run: |
61-
gh run download ${{ steps.find-run.outputs.run_id }} \
62-
--name github_metadata \
63-
--dir data/github_metadata
64-
6548
- name: Build 🔧 # Outputs the result to the 'build' folder.
6649
run: pnpm run build
6750
env:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ yarn-error.log*
4040
.netlify
4141

4242
/bazel-*
43-
/data/github_metadata/*.json

data/githubMetadata.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

data/github_metadata/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

data/moduleStaticProps.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ModuleInfo,
88
reverseDependencies,
99
} from './utils'
10-
import { getGithubRepositoryMetadata } from './githubMetadata'
1110

1211
export interface VersionInfo {
1312
version: string
@@ -45,19 +44,12 @@ export const getStaticPropsModulePage = async (
4544
const latestVersion = versions[0]
4645
const selectedVersion = version || latestVersion
4746

48-
// Get GitHub metadata from static JSON files
49-
const githubMetadata = await getGithubRepositoryMetadata(module)
50-
if (!githubMetadata) {
51-
console.warn(`No GitHub metadata found for module ${module}`)
52-
}
53-
5447
return {
5548
props: {
5649
metadata,
5750
versionInfos,
5851
selectedVersion,
5952
reverseDependencies: await reverseDependencies(module),
60-
githubMetadata,
6153
},
6254
}
6355
}

pages/modules/[module].tsx

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
getStaticPropsModulePage,
1818
VersionInfo,
1919
} from '../../data/moduleStaticProps'
20-
import { GithubRepositoryMetadata } from '../../data/githubMetadata'
2120
import { formatDistance, parseISO } from 'date-fns'
2221
import { faGlobe, faScaleBalanced } from '@fortawesome/free-solid-svg-icons'
2322

@@ -26,7 +25,6 @@ interface ModulePageProps {
2625
versionInfos: VersionInfo[]
2726
selectedVersion: string
2827
reverseDependencies: string[]
29-
githubMetadata: GithubRepositoryMetadata | null
3028
}
3129

3230
const GITHUB_API_USER_AGENT = 'Bazel Central Registry UI'
@@ -42,7 +40,6 @@ const ModulePage: NextPage<ModulePageProps> = ({
4240
versionInfos,
4341
selectedVersion,
4442
reverseDependencies,
45-
githubMetadata,
4643
}) => {
4744
const router = useRouter()
4845
const { module } = router.query
@@ -64,11 +61,12 @@ const ModulePage: NextPage<ModulePageProps> = ({
6461
selectedVersion
6562
)
6663

67-
// Use GitHub metadata from static build-time data instead of client-side hook
68-
const repoDescription = githubMetadata?.description || undefined
69-
const repoLicense = githubMetadata?.license || undefined
70-
const repoTopics = githubMetadata?.topics || undefined
71-
const repoStargazers = githubMetadata?.stargazers || undefined
64+
const {
65+
description: repoDescription,
66+
license: repoLicense,
67+
topics: repoTopics,
68+
stargazers: repoStargazers,
69+
} = useGithubMetadata(firstGithubRepository)
7270

7371
const isQualifiedForShowAllVersions =
7472
versionInfos.length > NUM_VERSIONS_ON_PAGE_LOAD
@@ -623,4 +621,60 @@ const useDetectReleaseFormatViaGithubApi = (
623621
return releaseTagFormat
624622
}
625623

624+
const useGithubMetadata = (metadataRepository: string | undefined) => {
625+
const githubOwnerAndRepo = metadataRepository?.replace('github:', '')
626+
const [description, setDescription] = useState<string | undefined>(undefined)
627+
const [license, setLicense] = useState<
628+
{ spdx_id: string; name: string; url: string } | undefined
629+
>()
630+
const [topics, setTopics] = useState<string[]>([])
631+
const [stargazers, setStargazers] = useState<number | undefined>(undefined)
632+
633+
useEffect(() => {
634+
const fetchRepoDescription = async () => {
635+
if (!githubOwnerAndRepo) {
636+
return
637+
}
638+
639+
try {
640+
const response = await fetch(
641+
`https://api.github.com/repos/${githubOwnerAndRepo}`,
642+
{
643+
method: 'GET',
644+
headers: {
645+
Accept: 'application/vnd.github+json',
646+
'User-Agent': GITHUB_API_USER_AGENT,
647+
'X-GitHub-Api-Version': GITHUB_API_VERSION,
648+
},
649+
}
650+
)
651+
652+
if (response.ok) {
653+
const repoData = await response.json()
654+
setStargazers(repoData.stargazers_count)
655+
setDescription(repoData.description)
656+
if (repoData.license) {
657+
setLicense(repoData.license)
658+
}
659+
660+
if (Array.isArray(repoData.topics)) {
661+
setTopics(repoData.topics)
662+
}
663+
}
664+
} catch (error) {
665+
console.error('Failed to fetch repository description:', error)
666+
}
667+
}
668+
669+
fetchRepoDescription()
670+
}, [githubOwnerAndRepo])
671+
672+
return {
673+
description,
674+
license,
675+
topics,
676+
stargazers,
677+
}
678+
}
679+
626680
export default ModulePage

0 commit comments

Comments
 (0)