Skip to content

Commit deeda99

Browse files
author
James Brundage
committed
test: SyncIssue with token ( re #91 ) [skip ci]
Syncing the top 100 issues
1 parent 67afa59 commit deeda99

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

Examples/SyncIssue.PSJekyll.ps1

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1+
param(
2+
# The issue state. Can be open, closed, or all
3+
[ValidateSet('open','closed','all')]
4+
[string]
5+
$IssueState = $(if ($env:IssueState) { $env:IssueState } else { 'all' }),
6+
7+
# The issue label.
8+
[string[]]
9+
$IssueLabel = $(if ($env:IssueLabel) { $env:IssueLabel } else { @() }),
10+
)
11+
112
if (-not $gitHubEvent.issue -and -not $gitHubEvent.discussion) {
213
Write-Warning "GitHub Event is not an issue or discussion, will not sync"
314
}
415

5-
Start-Sleep -Seconds (Get-Random -Minimum 10 -Maximum 20)
6-
git merge origin/main | Out-Host
7-
git pull | Out-Host
8-
9-
if ($GitHubToken) {
16+
if ($env:GitHubToken) {
1017
"GitHub Token is present" | Out-Host
1118
}
12-
if ($GitHubToken -and $env:GIHUB_REPOSIORY) {
13-
$owner, $repo = $env:GIHUB_REPOSIORY -split '/'
19+
if ($GitHubToken -and $env:GITHUB_REPOSIORY) {
20+
$owner, $repo = $env:GITHUB_REPOSIORY -split '/'
1421
"Getting issues for $owner, $repo" | Out-Host
22+
$queryString = @(
23+
if ($IssueState) {
24+
"state=$($issueState.ToLower())"
25+
}
26+
if ($IssueLabel) {
27+
"labels=$($IssueLabel -join ',')"
28+
}
29+
'per_page=100'
30+
) -join '&'
31+
$issues =
32+
Invoke-RestMethod -Uri "https://api.github.com/repos/$owner/$repo/issues?$queryString" -Headers @{
33+
"Authorization" = "token $GitHubToken"
34+
}
35+
foreach ($issue in $issues) {
36+
$psJekyll.CurrentSite.Data = @{"issues/$($issue.number)" = $issue}
37+
}
1538
} else {
1639
if ($gitHubEvent.issue) {
1740
$psJekyll.CurrentSite.Data = @{"issues/$($gitHubEvent.issue.number)" = $gitHubEvent.issue}

0 commit comments

Comments
 (0)