Skip to content

Commit 845729b

Browse files
authored
Add GitHub integration (#1)
1 parent 8048c28 commit 845729b

7 files changed

Lines changed: 122 additions & 54 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Defining groups of labels that can be imported to other projects and groups for
1515
## Instalation
1616

1717
```bash
18-
git clone https://gccode.ssc-spc.gc.ca/iitb-dgiit/esdc-labels.git
18+
git clone https://gccode.ssc-spc.gc.ca/esdc-edsc/label-generator.git
1919
```
2020

2121
Double click `quicklaunch.bat`
@@ -27,6 +27,13 @@ You will also need to be able to provide information about the project you want
2727

2828
### Details
2929

30+
#### GitHub details
31+
32+
* Personal access token https://github.com/settings/tokens
33+
34+
35+
#### GitLab details
36+
3037
* Project ID or Group ID
3138
Found in Project > Settings > General > General project > Project ID
3239
Or Group > Settings > General > Naming, visibility > Group ID

priority/labels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Read more about it in [GitLab Docs](https://docs.gitlab.com/ee/user/project/labe
2424
- priority::7
2525
- priority::8
2626
- priority::9
27-
- priority::10
27+
- priority::10

scripts/add.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
$accessToken = $args[0];
2-
$gitlabLink = $args[1];
3-
$jsonFile = $args[2];
1+
$hublab = $args[0];
2+
$accessToken = $args[1];
3+
$gitLink = $args[2];
4+
$jsonFile = $args[3];
45

56
$labelData = (Get-Content $jsonFile | Out-String | ConvertFrom-Json)
67

7-
Foreach ($label in $labelData)
8-
{
8+
Foreach ($label in $labelData) {
99
$name = $label.name
1010
$color = $label.color
1111
$desc = $label.desc
@@ -14,5 +14,13 @@ Foreach ($label in $labelData)
1414

1515
"
1616
Add '$name' label"
17-
curl --data "name=$name&color=$color&description=$desc" --header "PRIVATE-TOKEN: $accessToken" "$gitlabLink"
18-
}
17+
18+
If ($hublab -eq "lab") {
19+
curl --data "name=$name&color=$color&description=$desc" --header "PRIVATE-TOKEN: $accessToken" "$gitLink"
20+
} Else {
21+
$user = $accessToken + ":x-oauth-basic"
22+
$color = $color -replace '#',''
23+
24+
curl -u $user --data "{\""name\"":\""$name\"",\""color\"":\""$color\""}" $gitLink
25+
}
26+
}

scripts/hub.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# variables
2+
$githubEnv
3+
$orgUser
4+
$repo
5+
$userToken
6+
7+
"
8+
Which GitHub enviornment are you using?
9+
1- GitHub.com
10+
0- Other"
11+
$githubEnvSelection = Read-Host
12+
13+
IF ($githubEnvSelection -eq 1) {
14+
$githubEnv = "github.com"
15+
} Else {
16+
$githubEnv = Read-Host -Prompt 'Please enter your GitHub enviornment.'
17+
}
18+
19+
"
20+
You have chosen to use 'https://$githubEnv/' as your enviornment for git.
21+
"
22+
23+
$orgUser = Read-Host -Prompt 'What is the name (url portion) of the organization or user for the repository?'
24+
$repo = Read-Host -Prompt 'What is the name (url portion) of the repository?'
25+
$userToken = Read-Host -Prompt 'What is your GitHub API User Token?'
26+
27+
## select and add labels
28+
.\scripts\select.ps1 $userToken "https://api.$githubEnv/repos/$orgUser/$repo/labels" "hub"

scripts/lab.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# variables
2+
$gitlabEnv
3+
$GorP
4+
$projectId
5+
$userToken
6+
7+
"
8+
Which GitLab enviornment are you using?
9+
1- GCCode
10+
2- GitLab.com
11+
0- Other"
12+
$gitlabEnvSelection = Read-Host
13+
14+
IF ($gitlabEnvSelection -eq 1) {
15+
$gitlabEnv = "gccode.ssc-spc.gc.ca"
16+
} ElseIf ($gitlabEnvSelection -eq 2) {
17+
$gitlabEnv = "gitlab.com"
18+
} Else {
19+
$gitlabEnv = Read-Host -Prompt 'Please enter your GitLab enviornment.'
20+
}
21+
22+
"
23+
You have chosen to use 'https://$gitlabEnv/' as your enviornment for git.
24+
"
25+
"In order to add labels to your project we will need some info about the project or group you want to add the labels to."
26+
27+
$GorP = Read-Host -Prompt 'Are you targeting a Group (G) or Project (p) for these labels? (enter G or p)'
28+
29+
IF ($GorP -eq "G") {
30+
$GorP = "groups"
31+
$projectId = Read-Host -Prompt 'What is the Group ID?'
32+
} Else {
33+
$GorP = "projects"
34+
$projectId = Read-Host -Prompt 'What is the Project ID?'
35+
}
36+
37+
$userToken = Read-Host -Prompt 'What is your GitLab API User Token?'
38+
39+
## select and add labels
40+
.\scripts\select.ps1 $userToken "https://$gitlabEnv/api/v4/$GorP/$projectId/labels" "lab"

scripts/select.ps1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
$userToken = $args[0];
22
$gitlabLink = $args[1];
3+
$hublab = $args[2];
34

45
$addMore = "n"
5-
$jsonFileList
66

77
# add different sets of labels
88
do {
@@ -12,14 +12,13 @@ do {
1212
1 - General labels
1313
2 - Dev labels
1414
3 - Priority labels
15-
4 - A11Y labels
16-
5 - Security labels"
15+
(In development: A11Y labels, Security labels)"
1716
$selection = Read-Host
1817

1918
IF ($selection -eq 0) {
20-
.\scripts\add.ps1 $userToken $gitlabLink ".\dev\key-list.json"
21-
.\scripts\add.ps1 $userToken $gitlabLink ".\general\key-list.json"
22-
.\scripts\add.ps1 $userToken $gitlabLink ".\priority\key-list.json"
19+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\dev\key-list.json"
20+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\general\key-list.json"
21+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\priority\key-list.json"
2322
} ElseIF ($selection -In 1..3) {
2423
$selectedType
2524
IF ($selection -eq 1) {
@@ -39,13 +38,13 @@ do {
3938
$levelSelection = Read-Host
4039

4140
IF (1, 2, 3 -contains $levelSelection) {
42-
.\scripts\add.ps1 $userToken $gitlabLink ".\$selectedType\key-list.json"
41+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\$selectedType\key-list.json"
4342
}
4443
If (2, 3 -contains $levelSelection) {
45-
.\scripts\add.ps1 $userToken $gitlabLink ".\$selectedType\standard-list.json"
44+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\$selectedType\standard-list.json"
4645
}
4746
IF (3 -contains $levelSelection) {
48-
.\scripts\add.ps1 $userToken $gitlabLink ".\$selectedType\extra-list.json"
47+
.\scripts\add.ps1 $hublab $userToken $gitlabLink ".\$selectedType\extra-list.json"
4948
}
5049
} Else {
5150
"This option is not avaliable yet."

scripts/start.ps1

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# output with plain text - spacing matters
22
"
33
====================================================================================
4-
| Thank you for using ESDC Labels! |
4+
| Thank you for using ESDC Label Generator! |
55
| We need some information from you before we start adding labels to your project. |
66
====================================================================================
77
"
88

99
# variables
10-
$gitlabEnv
11-
$projectId
12-
$userToken
10+
$gitPlatform
1311
$curlLocation
14-
$GorP
1512

1613
# gather info
1714

18-
"Where do you have curl.exe installed?
15+
"
16+
Where do you have curl.exe installed?
1917
1- C:\Git\Git\mingw64\bin\curl.exe
2018
2- C:\Windows\System32\curl\curl.exe
2119
3- C:\Windows\SysWOW64\curl\curl.exe
@@ -36,39 +34,27 @@ IF ($curlSelector -eq 1) {
3634
Remove-Item alias:curl
3735
Set-Alias -Name curl -Value "$curlLocation"
3836

39-
"Which GitLab enviornment are you using?
40-
1- GCCode
41-
2- GitLab.com
42-
0- Other"
43-
$gitlabEnvSelection = Read-Host
44-
45-
IF ($gitlabEnvSelection -eq 1) {
46-
$gitlabEnv = "gccode.ssc-spc.gc.ca"
47-
} ElseIf ($gitlabEnvSelection -eq 2) {
48-
$gitlabEnv = "gitlab.com"
49-
} Else {
50-
$gitlabEnv = Read-Host -Prompt 'Please enter your GitLab enviornment.'
51-
}
52-
53-
"
54-
You have chosen to use 'https://$gitlabEnv/' as your enviornment for gitlab.
55-
"
56-
"In order to add labels to your project we will need some info about the project or group you want to add the labels to."
57-
58-
$GorP = Read-Host -Prompt 'Are you targeting a Group (G) or Project (p) for these labels? (enter G or p)'
59-
60-
IF ($GorP -eq "G") {
61-
$GorP = "groups"
62-
$projectId = Read-Host -Prompt 'What is the Group ID?'
63-
} Else {
64-
$GorP = "projects"
65-
$projectId = Read-Host -Prompt 'What is the Project ID?'
37+
$gitPlatform = ""
38+
While ($gitPlatform -eq "") {
39+
"
40+
Which Git platform are you using?
41+
1- GitHub
42+
2- GitLab
43+
(Sorry, we don't support any other platforms at the moment.)"
44+
$gitPatformSelection = Read-Host
45+
46+
IF ($gitPatformSelection -eq 1) {
47+
$gitPlatform = "hub"
48+
.\scripts\hub.ps1
49+
} ElseIf ($gitPatformSelection -eq 2) {
50+
$gitPlatform = "lab"
51+
.\scripts\lab.ps1
52+
} Else {
53+
"Sorry, you must select one of the options to continue."
54+
}
6655
}
6756

68-
$userToken = Read-Host -Prompt 'What is your User Token?'
6957

70-
## select and add labels
71-
.\scripts\select.ps1 $userToken "https://$gitlabEnv/api/v4/$GorP/$projectId/labels"
7258

7359
"
7460
Thanks for using ESDC Labels!

0 commit comments

Comments
 (0)