Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Fix bad object error fetch (#46)
Browse files Browse the repository at this point in the history
* fix the targetBase ref

* cleanup
  • Loading branch information
leordev authored Oct 19, 2023
1 parent 4d2d953 commit fe67aaa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: npm

- name: Install Dependencies
Expand Down Expand Up @@ -54,6 +54,7 @@ jobs:
with:
fail_on_error: true
fail_on_warnings: true
report_changed_scope_only: false
bot_app_id: ${{ secrets.BOT_APP_ID }}
bot_app_private_key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
bot_app_installation_id: ${{ secrets.BOT_APP_INSTALLATION_ID }}
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ export type FilesDiffsMap = Record<string, GitDiffs[]>
const git = simpleGit()

export const getFilesDiffs = async (): Promise<FilesDiffsMap> => {
const targetBase = getBaseInfo() || { ref: 'main', sha: undefined }
const targetBase = getBaseInfo() || { ref: 'main' }

// Since GH Actions checkout action doesn't fetch all the history, we need to do it manually
await fetchGitHistory(targetBase.ref)
const targetSha = await fetchGitHistory(targetBase.ref)
console.info(`Git history fetched ref '${targetBase.ref}' successfully!`)

const targetShaOrRef = targetBase.sha || targetBase.ref

const diffSummary = await git.diffSummary(['-U0', targetShaOrRef])
const diffSummary = await git.diffSummary(['-U0', targetSha])

const filesDiffsMap: FilesDiffsMap = {}

for (const file of diffSummary.files) {
const fileDiffs = await getFileDiffs(targetShaOrRef, file.file)
const fileDiffs = await getFileDiffs(targetSha, file.file)

const changedLines: GitDiffs[] = fileDiffs
.split('\n')
Expand All @@ -68,10 +66,7 @@ export const getFilesDiffs = async (): Promise<FilesDiffsMap> => {
filesDiffsMap[fullFilePath] = changedLines
}

console.info(
`>>> Files diffs map comparing with ${targetShaOrRef}`,
filesDiffsMap
)
console.info(`>>> Files diffs map comparing with ${targetSha}`, filesDiffsMap)
return filesDiffsMap
}

Expand Down Expand Up @@ -116,7 +111,7 @@ export const isSourceInChangedScope = (
)
}

const fetchGitHistory = async (targetBranch: string): Promise<void> => {
const fetchGitHistory = async (targetBranch: string): Promise<string> => {
// needed for the docker container to work
console.info(">>> Setting git config 'safe.directory' to '/github/workspace'")

Expand All @@ -137,4 +132,9 @@ const fetchGitHistory = async (targetBranch: string): Promise<void> => {
'origin',
`+refs/heads/${targetBranch}:refs/remotes/origin/${targetBranch}`
])

const sha = await git.revparse([`origin/${targetBranch}`])
console.info(`>>> Origin fetched sha: ${sha}`)

return sha
}

0 comments on commit fe67aaa

Please sign in to comment.