-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGitHubRepository.ps1
More file actions
374 lines (322 loc) · 15.1 KB
/
GitHubRepository.ps1
File metadata and controls
374 lines (322 loc) · 15.1 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
class GitHubRepository : GitHubNode {
# The name of the repository.
# Example: Team Environment
[string] $Name
# The owner of the repository.
# Example: octocat
[GitHubOwner] $Owner
# The full name of the repository, including the owner.
# Example: octocat/Hello-World
[string] $FullName
# The HTML URL of the repository.
# Example: https://github.com/octocat/Hello-World
[string] $Url
# The description of the repository.
# Example: This your first repo!
[string] $Description
# The date and time the repository was created.
# Example: 2011-01-26T19:01:12Z
[System.Nullable[datetime]] $CreatedAt
# The date and time the repository was last updated.
# Example: 2011-01-26T19:14:43Z
[System.Nullable[datetime]] $UpdatedAt
# The date and time of the last push.
# Example: 2011-01-26T19:06:43Z
[System.Nullable[datetime]] $PushedAt
# The date and time when the repository was archived.
# Example: 2011-01-26T19:01:12Z
[System.Nullable[datetime]] $ArchivedAt
# The homepage URL.
# Example: https://github.com
[string] $Homepage
# The size of the repository, in bytes.
# Example: 110592
[System.Nullable[uint64]] $Size
# The primary language of the repository.
# Example: null
[GitHubRepositoryLanguage] $Language
# Whether issues are enabled.
# Example: true
[System.Nullable[bool]] $HasIssues
# Whether projects are enabled.
# Example: true
[System.Nullable[bool]] $HasProjects
# Whether the wiki is enabled.
# Example: true
[System.Nullable[bool]] $HasWiki
# Whether pages are enabled.
# Example: false
[System.Nullable[bool]] $HasPages
# Whether discussions are enabled.
# Example: true
[System.Nullable[bool]] $HasDiscussions
# Whether sponsorships are enabled.
# Example: false
[System.Nullable[bool]] $HasSponsorships
# Indicates whether the repository is archived.
# Example: false
[System.Nullable[bool]] $IsArchived
# Indicates whether the repository acts as a template.
# Example: true
[System.Nullable[bool]] $IsTemplate
# Indicates whether the repository is a fork.
# Example: false
[System.Nullable[bool]] $IsFork
# License information for the repository.
# Example: 'MIT License', 'Mozilla Public License 2.0'
[GitHubLicense] $License
# Whether to allow forking this repository.
# Example: true
[System.Nullable[bool]] $AllowForking
# Whether to require contributors to sign off on web-based commits
# Example: false
[System.Nullable[bool]] $RequireWebCommitSignoff
# The topics associated with the repository.
# Example: @()
[string[]] $Topics
# The visibility of the repository (public, private, or internal).
# Example: public
[string] $Visibility
# The number of open issues.
# Example: 15
[System.Nullable[uint]] $OpenIssues
# The number of open pull requests.
# Example: 15
[System.Nullable[uint]] $OpenPullRequests
# The number of stargazers.
# Example: 80
[System.Nullable[uint]] $Stargazers
# The number of watchers.
# Example: 80
[System.Nullable[uint]] $Watchers
# The number of forks.
# Example: 9
[System.Nullable[uint]] $Forks
# The default branch of the repository.
# Example: main
[string] $DefaultBranch
# Permission on the repository.
# Example: 'Admin'
[string] $Permission
# Whether to allow squash merges for pull requests.
# Example: true
[System.Nullable[bool]] $AllowSquashMerge
# Whether to allow merge commits for pull requests.
# Example: true
[System.Nullable[bool]] $AllowMergeCommit
# Whether to allow rebase merges for pull requests.
# Example: true
[System.Nullable[bool]] $AllowRebaseMerge
# Whether to allow auto-merge on pull requests.
# Example: false
[System.Nullable[bool]] $AllowAutoMerge
# Whether to delete head branches when pull requests are merged.
# Example: false
[System.Nullable[bool]] $DeleteBranchOnMerge
# Whether a pull request head branch is suggested to be updated if behind its base branch.
# Example: false
[System.Nullable[bool]] $SuggestUpdateBranch
# The default value for a squash merge commit title.
# Enum: PR_TITLE, COMMIT_OR_PR_TITLE
# Example: PR_TITLE
[string] $SquashMergeCommitTitle
# The default value for a squash merge commit message.
# Enum: PR_BODY, COMMIT_MESSAGES, BLANK
# Example: PR_BODY
[string] $SquashMergeCommitMessage
# The default value for a merge commit title.
# Enum: PR_TITLE, MERGE_MESSAGE
# Example: PR_TITLE
[string] $MergeCommitTitle
# The default value for a merge commit message.
# Enum: PR_BODY, PR_TITLE, BLANK
# Example: PR_TITLE
[string] $MergeCommitMessage
# The template repository that this repository was created from
[GithubRepository] $TemplateRepository
# The repository this repository was forked from.
[GithubRepository] $ForkRepository
# Custom properties for the repository.
[GitHubCustomProperty[]] $CustomProperties
# The clone URL of the repository.
# Example: git://github.com/octocat/Hello-World.git
[string] $CloneUrl
# The SSH URL of the repository.
# Example: git@github.com:octocat/Hello-World.git
[string] $SshUrl
# The Git URL of the repository.
# Example: https://github.com/octocat/Hello-World.git
[string] $GitUrl
# Mapping of property names to GitHub GraphQL query syntax
static [hashtable] $PropertyToGraphQLMap = @{
Name = 'name'
Owner = 'owner { login }'
FullName = 'name', 'owner { login }'
Url = 'url'
Description = 'description'
CreatedAt = 'createdAt'
UpdatedAt = 'updatedAt'
PushedAt = 'pushedAt'
ArchivedAt = 'archivedAt'
Homepage = 'homepageUrl'
Size = 'diskUsage'
Language = 'primaryLanguage { name id color }'
HasIssues = 'hasIssuesEnabled'
HasProjects = 'hasProjectsEnabled'
HasWiki = 'hasWikiEnabled'
HasDiscussions = 'hasDiscussionsEnabled'
HasSponsorships = 'hasSponsorshipsEnabled'
IsArchived = 'isArchived'
IsTemplate = 'isTemplate'
IsFork = 'isFork'
License = 'licenseInfo { name key spdxId }'
AllowForking = 'forkingAllowed'
RequireWebCommitSignoff = 'webCommitSignoffRequired'
Topics = 'repositoryTopics(first: 20) { nodes { topic { name } } }'
Visibility = 'visibility'
OpenIssues = 'issues { totalCount }'
OpenPullRequests = 'pullRequests { totalCount }'
Stargazers = 'stargazers { totalCount }'
Watchers = 'watchers { totalCount }'
Forks = 'forks { totalCount }'
DefaultBranch = 'defaultBranchRef { name }'
Permission = 'viewerPermission'
AllowSquashMerge = 'squashMergeAllowed'
AllowMergeCommit = 'mergeCommitAllowed'
AllowRebaseMerge = 'rebaseMergeAllowed'
AllowAutoMerge = 'autoMergeAllowed'
DeleteBranchOnMerge = 'deleteBranchOnMerge'
SuggestUpdateBranch = 'allowUpdateBranch'
SquashMergeCommitTitle = 'squashMergeCommitTitle'
SquashMergeCommitMessage = 'squashMergeCommitMessage'
MergeCommitTitle = 'mergeCommitTitle'
MergeCommitMessage = 'mergeCommitMessage'
TemplateRepository = 'templateRepository { id databaseId name owner { login } }'
ForkRepository = 'parent { id databaseId name owner { login } }'
CustomProperties = 'repositoryCustomPropertyValues(first: 100) { nodes { propertyName value } }'
CloneUrl = 'url'
SshUrl = 'sshUrl'
GitUrl = 'url'
NodeID = 'id'
ID = 'databaseId'
}
GitHubRepository() {}
GitHubRepository([PSCustomObject]$Object) {
if ($null -ne $Object.node_id) {
$this.ID = $Object.id
$this.NodeID = $Object.node_id
$this.Name = $Object.name
$this.Owner = [GitHubOwner]::New($Object.owner)
$this.FullName = $Object.full_name
$this.Visibility = $Object.visibility ? (Get-Culture).TextInfo.ToTitleCase($Object.visibility.ToLower()) : $null
$this.Description = $Object.description
$this.Homepage = $Object.homepage
$this.Url = $Object.html_url
if ($null -ne $Object.size) {
$this.Size = [uint64]($Object.size * 1KB)
}
$this.Language = [GitHubRepositoryLanguage]::new($Object.language)
$this.IsFork = $Object.fork
$this.IsArchived = $Object.archived
$this.IsTemplate = $Object.is_template
$this.HasIssues = $Object.has_issues
$this.HasProjects = $Object.has_projects
$this.HasWiki = $Object.has_wiki
$this.HasDiscussions = $Object.has_discussions
$this.HasPages = $Object.has_pages
$this.AllowForking = $Object.allow_forking
$this.License = [GitHubLicense]::New($Object.license)
$this.RequireWebCommitSignoff = $Object.web_commit_signoff_required
$this.CreatedAt = $Object.created_at
$this.UpdatedAt = $Object.created_at
$this.PushedAt = $Object.pushed_at
$this.Topics = $Object.topics
$this.Forks = $Object.forks_count
$this.OpenIssues = $Object.open_issues_count
$this.Watchers = $Object.watchers_count
$this.Stargazers = $Object.stargazers_count
$this.DefaultBranch = $Object.default_branch
$this.Permission = [GitHubRepositoryPermission]::GetPermissionString($Object.permissions)
$this.AllowSquashMerge = $Object.allow_squash_merge
$this.AllowMergeCommit = $Object.allow_merge_commit
$this.AllowRebaseMerge = $Object.allow_rebase_merge
$this.AllowAutoMerge = $Object.allow_auto_merge
$this.DeleteBranchOnMerge = $Object.delete_branch_on_merge
$this.SuggestUpdateBranch = $Object.allow_update_branch
$this.SquashMergeCommitMessage = $Object.squash_merge_commit_message
$this.SquashMergeCommitTitle = $Object.squash_merge_commit_title
$this.MergeCommitMessage = $Object.merge_commit_message
$this.MergeCommitTitle = $Object.merge_commit_title
$this.CustomProperties = $Object.custom_properties | ForEach-Object {
[GitHubCustomProperty]::new($_)
}
$this.TemplateRepository = $null -ne $Object.template_repository ? [GitHubRepository]::New($Object.template_repository) : $null
$this.ForkRepository = $null -ne $Object.parent ? [GitHubRepository]::New($Object.parent) : $null
$this.CloneUrl = $Object.clone_url
$this.SshUrl = $Object.ssh_url
$this.GitUrl = $Object.git_url
} else {
$this.ID = $Object.databaseId
$this.NodeID = $Object.id
$this.Name = $Object.name
$this.Owner = [GitHubOwner]::New($Object.owner)
if (-not ([string]::IsNullOrEmpty($this.Owner) -or [string]::IsNullOrEmpty($this.Name))) {
$this.FullName = "$($this.Owner)/$($this.Name)"
}
$this.Url = $Object.url
$this.Description = $Object.description
$this.CreatedAt = $Object.createdAt
$this.UpdatedAt = $Object.updatedAt
$this.PushedAt = $Object.pushedAt
$this.ArchivedAt = $Object.archivedAt
$this.Homepage = $Object.homepageUrl
if ($null -ne $Object.diskUsage) {
$this.Size = [uint64]($Object.diskUsage * 1KB)
}
$this.Language = [GitHubRepositoryLanguage]::new($Object.primaryLanguage)
$this.HasIssues = $Object.hasIssuesEnabled
$this.HasProjects = $Object.hasProjectsEnabled
$this.HasWiki = $Object.hasWikiEnabled
$this.HasDiscussions = $Object.hasDiscussionsEnabled
$this.HasSponsorships = $Object.hasSponsorshipsEnabled
$this.IsArchived = $Object.isArchived
$this.IsTemplate = $Object.isTemplate
$this.IsFork = $Object.isFork
$this.License = [GitHubLicense]::new($Object.licenseInfo)
$this.AllowForking = $Object.forkingAllowed
$this.RequireWebCommitSignoff = $Object.webCommitSignoffRequired
$this.Topics = $Object.repositoryTopics.nodes.topic.name
$this.Visibility = $Object.visibility ? (Get-Culture).TextInfo.ToTitleCase($Object.visibility.ToLower()) : $null
$this.OpenIssues = $Object.issues.totalCount
$this.OpenPullRequests = $Object.pullRequests.totalCount
$this.Stargazers = $Object.stargazers.totalCount
$this.Watchers = $Object.watchers.totalCount
$this.Forks = $Object.forks.totalCount
$this.DefaultBranch = $Object.defaultBranchRef.name
$this.Permission = [GitHubRepositoryPermission]::GetPermissionString($Object.viewerPermission)
$this.AllowSquashMerge = $Object.squashMergeAllowed
$this.AllowMergeCommit = $Object.mergeCommitAllowed
$this.AllowRebaseMerge = $Object.rebaseMergeAllowed
$this.AllowAutoMerge = $Object.autoMergeAllowed
$this.DeleteBranchOnMerge = $Object.deleteBranchOnMerge
$this.SuggestUpdateBranch = $Object.allowUpdateBranch
$this.SquashMergeCommitTitle = $Object.squashMergeCommitTitle
$this.SquashMergeCommitMessage = $Object.squashMergeCommitMessage
$this.MergeCommitTitle = $Object.mergeCommitTitle
$this.MergeCommitMessage = $Object.mergeCommitMessage
if ($null -ne $Object.repositoryCustomPropertyValues -and $null -ne $Object.repositoryCustomPropertyValues.nodes) {
$this.CustomProperties = $Object.repositoryCustomPropertyValues.nodes | ForEach-Object {
[GitHubCustomProperty]::new($_)
}
}
$this.TemplateRepository = $null -ne $Object.templateRepository ? [GitHubRepository]::New($Object.templateRepository) : $null
$this.ForkRepository = $null -ne $Object.parent ? [GitHubRepository]::New($Object.parent) : $null
$this.CloneUrl = -not [string]::IsNullOrEmpty($Object.url) ? $Object.url + '.git' : $null
$this.SshUrl = $Object.sshUrl
$this.GitUrl = -not [string]::IsNullOrEmpty($Object.url) ? ($Object.Url + '.git').Replace('https://', 'git://') : $null
}
}
[string] ToString() {
return $this.Name
}
}