Skip to content

Commit

Permalink
fix: using GitHub API causes an HTTP error
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Dec 11, 2023
1 parent 3d3561f commit 8032856
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Branches = await ListBranches(ProgramOptions).then(Branches => Branches)
const PurgeRequest = new PurgeRequestManager(ProgramOptions)
for (const Branch of Branches) {
// eslint-disable-next-line no-await-in-loop
const CommitSHA = await GetCommitSHAFromLatestWorkflowTime(ProgramOptions, LatestWorkflowRunTime, Branch).then(CommitSHA => CommitSHA)
const CommitSHA = await GetCommitSHAFromLatestWorkflowTime(ProgramOptions, LatestWorkflowRunTime, Branch, Branches[1]).then(CommitSHA => CommitSHA)
var ChangedFiles: string[] = []
if (CommitSHA.length === 0) {
continue
Expand Down
2 changes: 1 addition & 1 deletion sources/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ export async function ListBranches(ProgramOptions: Types.ProgramOptionsType): Pr
Actions.debug(`ListBranches in branches.ts called: ${JSON.stringify(Branches)}`)
}

return Branches
return Branches.filter(Branch => Branch !== undefined && Branch !== null)
}
6 changes: 3 additions & 3 deletions sources/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ function CreateGitInstance(BasePath: string): Git.SimpleGit {
* @param {string} Branch The branch or tag name.
* @returns {Promise<Types.CommitSHA>} SHA of the latest commit.
*/
export async function GetCommitSHAFromLatestWorkflowTime(ProgramOptions: Types.ProgramOptionsType, LatestWorkflowRunTime: number, Branch: string): Promise<Types.CommitSHA> {
export async function GetCommitSHAFromLatestWorkflowTime(ProgramOptions: Types.ProgramOptionsType, LatestWorkflowRunTime: number, Branch: string, DefaultBranch: string): Promise<Types.CommitSHA> {
var MatchedCommitTimeAddress = 0
if (ProgramOptions.shouldUseApi) {
const GitHubInstance = CreateGitHubInstance(ProgramOptions)
const GitHubListCommits = await GitHubInstance.repos.listCommits({
owner: ProgramOptions.repo.split('/')[0],
repo: ProgramOptions.repo.split('/')[1],
sha: Branch,
sha: Branch === 'latest' ? DefaultBranch : Branch,
}).then(Response => Response.data)
for (const CommitRaw of GitHubListCommits) {
if (DateTime.fromISO(CommitRaw.commit.author.date).toMillis() < LatestWorkflowRunTime) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function GetChangedFilesFromSHAToHead(ProgramOptions: Types.Program
const GitHubComparingRaw = await GitHubInstance.repos.compareCommits({
owner: ProgramOptions.repo.split('/')[0],
repo: ProgramOptions.repo.split('/')[1],
head: Branch,
head: Branch === 'latest' ? DefaultBranch : Branch,
base: CommitSHA,
}).then(Response => Response.data)
return GitHubComparingRaw.files.map(File => File.filename)
Expand Down

0 comments on commit 8032856

Please sign in to comment.