-
Notifications
You must be signed in to change notification settings - Fork 1
/
Import-FullCommits.ps1
57 lines (38 loc) · 1.44 KB
/
Import-FullCommits.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
param($accessToken)
. .\helpers.ps1
$repoUrl = "https://api.github.com/repos/kunzimariano/CommitService.DemoRepo"
$eventStore = 'http://127.0.0.1:2113'
$eventStore += '/streams/github-events'
function Get-CommitsLinks {
$currentUrl = "$repoUrl/commits?per_page=100&page=1"
$commitsUrls = @()
do {
$currentUrl = Get-AccesToken $currentUrl $accessToken
$response = Invoke-WebRequest -Uri $currentUrl
(ConvertFrom-Json $response.Content) | % {
$commitsUrls += $_.url
}
$currentUrl = Get-NextLink $response.Headers
} while($currentUrl -ne $null)
$commitsUrls
}
function Import-FullCommits {
param($links)
$commitsEvents = @()
for($i = ($links.Length -1); $i -gt -1; $i--) {
$currentUrl = Get-AccesToken ($links[$i]) $accessToken
$response = Invoke-WebRequest -Uri $currentUrl
$commit = ConvertFrom-Json $response.Content
$commitsEvents += Get-EsCommitEvent $commit
}
$events = ConvertTo-Json $commitsEvents -Depth 6
$auth = Get-AuthorizationHeader
$headers = @{
"Accept" = "application/json";
"Content-Type" = "application/vnd.eventstore.events+json";
"Content-Length" = $esEvents.Length;
"Authorization" = $auth
}
Invoke-WebRequest -Body $events -Uri $eventStore -Method Post -Headers $headers
}
Import-FullCommits (Get-CommitsLinks)