-
Notifications
You must be signed in to change notification settings - Fork 3
/
CreateDefaultRepoCommand.cs
103 lines (93 loc) · 4.83 KB
/
CreateDefaultRepoCommand.cs
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
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Git.Common;
using System;
namespace TfsGitAdmin
{
class CreateDefaultRepoCommand : GitAdminBaseCommand
{
internal string AdditionalRepoName { get; set; }
public CreateDefaultRepoCommand()
{
this.IsCommand("create", "Creates the default Git repository on a Team Project without version control");
}
public override int Run(string[] remainingArguments)
{
Console.WriteLine("Creating default Git repository in {0}/{1}/{2}", TfsUrl, TeamProjectCollection, TeamProject);
Connect();
var identityManagementService = tpc.GetService<IIdentityManagementService>();
//collection default groups
var identityProjectCollectionAdministrators = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Project Collection Administrators", TeamProjectCollection),
MembershipQuery.None,
ReadIdentityOptions.None);
var identityProjectCollectionBuildServiceAccounts = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Project Collection Build Service Accounts", TeamProjectCollection),
MembershipQuery.None,
ReadIdentityOptions.None);
var identityProjectCollectionServiceAccounts = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Project Collection Service Accounts", TeamProjectCollection),
MembershipQuery.None,
ReadIdentityOptions.None);
//project default groups
var identityBuildAdministrators = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Build Administrators", TeamProject),
MembershipQuery.None,
ReadIdentityOptions.None);
var identityContributors = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Contributors", TeamProject),
MembershipQuery.None,
ReadIdentityOptions.None);
var identityProjectAdministrators = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Project Administrators", TeamProject),
MembershipQuery.None,
ReadIdentityOptions.None);
var identityReaders = identityManagementService.ReadIdentity(
IdentitySearchFactor.DisplayName,
string.Format(@"[{0}]\Readers", TeamProject),
MembershipQuery.None,
ReadIdentityOptions.None);
var aces = new AccessControlEntry[] {
new AccessControlEntry(
identityProjectCollectionAdministrators.Descriptor,
GitRepositoryPermissions.All, 0),
new AccessControlEntry(
identityProjectCollectionBuildServiceAccounts.Descriptor,
GitRepositoryPermissions.GenericRead, 0),
new AccessControlEntry(
identityProjectCollectionServiceAccounts.Descriptor,
GitRepositoryPermissions.All, 0),
new AccessControlEntry(
identityBuildAdministrators.Descriptor,
GitRepositoryPermissions.CreateBranch
| GitRepositoryPermissions.GenericContribute
| GitRepositoryPermissions.ManageNote
| GitRepositoryPermissions.GenericRead
| GitRepositoryPermissions.CreateTag
, 0),
new AccessControlEntry(
identityContributors.Descriptor,
GitRepositoryPermissions.CreateBranch
| GitRepositoryPermissions.GenericContribute
| GitRepositoryPermissions.ManageNote
| GitRepositoryPermissions.GenericRead
| GitRepositoryPermissions.CreateTag
, 0),
new AccessControlEntry(
identityProjectAdministrators.Descriptor,
GitRepositoryPermissions.All, 0),
new AccessControlEntry(
identityReaders.Descriptor,
GitRepositoryPermissions.GenericRead, 0),
};
gitSvc.CreateTeamProjectRepository(TeamProject, aces);
return 0;
}
}
}