-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed bug of deleting more than expected. #3250
Changes from 11 commits
4d03cc6
f7ad031
8865aaa
fe1d94e
6e6789c
40b165f
9405b70
1340850
c4004c9
d1a3e81
54a6ae0
03c4132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,8 @@ foreach ($res in $responses) | |
continue | ||
} | ||
$branch = $res.ref | ||
$branchName = $branch.Replace("refs/heads/","") | ||
try { | ||
$branchName = $branch.Replace("refs/heads/","") | ||
$head = "${RepoId}:${branchName}" | ||
LogDebug "Operating on branch [ $branchName ]" | ||
$pullRequests = Get-GitHubPullRequests -RepoId $RepoId -State "all" -Head $head -AuthToken $AuthToken | ||
|
@@ -53,26 +53,29 @@ foreach ($res in $responses) | |
continue | ||
} | ||
|
||
LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has no associated open Pull Request. " | ||
if ($LastCommitOlderThan) { | ||
if (!$res.object -or !$res.object.url) { | ||
LogWarning "No commit url returned from response. Skipping... " | ||
continue | ||
} | ||
try { | ||
$commitDate = Get-GithubReferenceCommitDate -commitUrl $res.object.url -AuthToken $AuthToken | ||
if ($commitDate -and ($commitDate -gt $LastCommitOlderThan)) { | ||
LogDebug "The branch $branch last commit date $commitDate is newer than the date $LastCommitOlderThan. Skipping." | ||
if (!$commitDate -or ($commitDate -gt $LastCommitOlderThan)) { | ||
LogDebug "No last commit date or the branch $branch last commit date [ $commitDate ] is newer than the date $LastCommitOlderThan. Skipping." | ||
continue | ||
} | ||
|
||
LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has a last commit date [ $commitDate ] that is older than $LastCommitOlderThan. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I generally use single quotes for special values in strings vs. brackets with spaces, as it will make your log statement shorter and easier to read without horizontal scrolling in some situations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is asking the change for the entire file. I am going to have follow up of switching github api to gh. I can make the changes over there. |
||
} | ||
catch { | ||
LogError "Get-GithubReferenceCommitDate failed with exception:`n$_" | ||
exit 1 | ||
} | ||
} | ||
LogDebug "Branch [ $branchName ] in repo [ $RepoId ] has no associated open Pull Request. " | ||
sima-zhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
Remove-GitHubSourceReferences -RepoId $RepoId -Ref $branch -AuthToken $AuthToken | ||
sima-zhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LogDebug "The branch [ $branchName ] in [ $RepoId ] has been deleted." | ||
} | ||
catch { | ||
LogError "Remove-GitHubSourceReferences failed with exception:`n$_" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you broke this up into two separate if+log statements then the reader wouldn't have to guess from the log which condition was true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.