|
35 | 35 | $org_user_admins_parameters = array($org, null, 'all', 'admin');
|
36 | 36 | $org_user_admins = $paginator->fetchAll($client->api('members'), 'all', $org_user_admins_parameters);
|
37 | 37 |
|
| 38 | +// I need these data to populate users list in users/vars.tf |
| 39 | +$github_user_logins = ""; |
| 40 | +foreach ($org_user_members as $github_user) { |
| 41 | + $github_user_logins = $github_user_logins . "\"" . $github_user['login'] . "\", "; |
| 42 | +} |
| 43 | + |
| 44 | +$github_admin_logins = ""; |
| 45 | +foreach ($org_user_admins as $github_user) { |
| 46 | + $github_admin_logins = $github_admin_logins . "\"" . $github_user['login'] . "\", "; |
| 47 | +} |
| 48 | + |
38 | 49 | /**
|
39 | 50 | * github_team:
|
40 | 51 | * name
|
|
59 | 70 | $repo_topics[$repo['name']] = $topic;
|
60 | 71 | }
|
61 | 72 | }
|
| 73 | + |
| 74 | +$repo_topics_as_str = array(); |
| 75 | +foreach ($repo_topics as $repo => $value) { |
| 76 | + $topics_as_a_string = ""; |
| 77 | + foreach ($value as $topics) { |
| 78 | + $topics_as_a_string = $topics_as_a_string . "\"," . $topics; |
| 79 | + } |
| 80 | + $repo_topics_as_str[$repo] = $topics_as_a_string; |
| 81 | +} |
62 | 82 | /*
|
63 | 83 | * To get protected branches I have modified Repo\brances() method
|
64 | 84 | * public function branches($username, $repository, $branch = null, array $params = [])
|
|
72 | 92 | }
|
73 | 93 | */
|
74 | 94 | // TODO: add these data to repo template
|
75 |
| -$protected_branches = array(); |
76 |
| -foreach ($org_repositories as $repo) { |
77 |
| - $parameters = array($org, $repo['name'], null, array("protected" => "true")); |
78 |
| - $protected_branches[$repo['name']] = $paginator->fetchAll($client->api('repositories'), 'branches', $parameters); |
79 |
| -} |
| 95 | +//$protected_branches = array(); |
| 96 | +//foreach ($org_repositories as $repo) { |
| 97 | +// $parameters = array($org, $repo['name'], null, array("protected" => "true")); |
| 98 | +// $protected_branches[$repo['name']] = $paginator->fetchAll($client->api('repositories'), 'branches', $parameters); |
| 99 | +//} |
80 | 100 |
|
81 | 101 | // TODO: add github branch protection. See https://www.terraform.io/docs/providers/github/r/branch_protection.html
|
82 | 102 | // TODO: add webhooks for a repo: https://www.terraform.io/docs/providers/github/r/repository_webhook.html
|
|
102 | 122 |
|
103 | 123 | $team_repositories = array();
|
104 | 124 | $team_repositories_with_permission = array();
|
| 125 | +$org_team_ids = array(); |
105 | 126 | foreach ($org_teams as $team) {
|
106 | 127 | $parameters = array($team['id']);
|
107 | 128 | foreach ($paginator->fetchAll($client->api('teams'), 'repositories', $parameters) as $rep) {
|
|
111 | 132 | }
|
112 | 133 | $team_repositories[$team['slug']] = $team_repositories_with_permission;
|
113 | 134 | $team_repositories_with_permission = array();
|
| 135 | + $org_team_ids[$team['slug']] = $team['id']; |
114 | 136 | }
|
115 | 137 |
|
116 | 138 | $org_team_members = array();
|
117 | 139 | $org_team_maintainers = array();
|
| 140 | +$org_team_members_ids = array(); |
| 141 | +$org_team_maintainers_ids = array(); |
118 | 142 | $team_maintainers = array();
|
119 | 143 | $team_members = array();
|
120 | 144 | /**
|
|
151 | 175 | $team_maintainers = array();
|
152 | 176 | }
|
153 | 177 |
|
154 |
| -$file = '/home/rmamaev/workspace/github-terraform-exporter/tf-commands.txt'; |
| 178 | +$file = '/home/ruslan.mamaev/workspace/github-terraform-exporter/tf-commands.txt'; |
155 | 179 |
|
156 | 180 | foreach ($org_teams as $team) {
|
157 | 181 | $command = "terraform import github_team.team_" . $team['slug'] . " " .
|
|
185 | 209 | file_put_contents($file, $command, FILE_APPEND);
|
186 | 210 | }
|
187 | 211 |
|
188 |
| -foreach ($team_members as $team => $users) { |
| 212 | +foreach ($org_team_members as $team => $users) { |
189 | 213 | foreach ($users as $user) {
|
190 |
| - $command = "terraform import github_team_membership.member " . $team . ":" . $user . "\n"; |
| 214 | + $command = "terraform import github_team_membership.team_" . $team . "_" . $user['login'] . "_membership" . |
| 215 | + " " . $org_team_ids[$team] . ":" . $user['login'] . "\n"; |
191 | 216 | file_put_contents($file, $command, FILE_APPEND);
|
192 | 217 | }
|
193 | 218 | }
|
194 | 219 |
|
195 |
| -foreach ($team_maintainers as $team => $users) { |
| 220 | +foreach ($org_team_maintainers as $team => $users) { |
196 | 221 | foreach ($users as $user) {
|
197 |
| - $command = "terraform import github_team_membership.member " . $team . ":" . $user . "\n"; |
| 222 | + $command = "terraform import github_team_membership.team_" . $team . "_" . $user['login'] . "_membership" . |
| 223 | + " " . $org_team_ids[$team] . ":" . $user['login'] . "\n"; |
198 | 224 | file_put_contents($file, $command, FILE_APPEND);
|
199 | 225 | }
|
200 | 226 | }
|
|
204 | 230 | require_once 'templates/org-users.php';
|
205 | 231 | require_once 'templates/teams.php';
|
206 | 232 | require_once 'templates/team-members.php';
|
| 233 | + |
0 commit comments