Skip to content

Commit e39c8c1

Browse files
committed
cli
1 parent c2c74d4 commit e39c8c1

File tree

4 files changed

+184
-10
lines changed

4 files changed

+184
-10
lines changed

confluence/serv/pages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (s PageService) CreateContent(url string, tok string, ctype string, key str
159159
Ancestors: ancts,
160160
}
161161
mrsCtn, err2 := json.Marshal(cntb)
162-
fmt.Println(string(mrsCtn))
162+
//fmt.Println(string(mrsCtn))
163163
if err2 != nil {
164164
log.Panicln(err2)
165165
}
@@ -180,7 +180,7 @@ func (s PageService) CreateContent(url string, tok string, ctype string, key str
180180
var content models.Content
181181
bts, err := io.ReadAll(resp.Body)
182182
err = json.Unmarshal(bts, &content)
183-
fmt.Println(string(bts))
183+
//fmt.Println(string(bts))
184184
return content
185185
}
186186

main.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log"
1010
"os"
1111
"runtime"
12+
"strings"
1213
"time"
1314
)
1415

@@ -27,12 +28,18 @@ func main() {
2728
var pageId string
2829
var pageTitle string
2930
var spaceKey string
31+
var parent string
32+
var body string
33+
var labels string
3034

3135
// jira
3236
var projKey string
3337
var projId string
3438
var issueKey string
3539

40+
//misc
41+
var file string
42+
3643
// create issue data
3744
var summary string
3845
var description string
@@ -41,7 +48,7 @@ func main() {
4148
var issueLabels []string
4249
var assignee string
4350
var reporter string
44-
var priorityName string
51+
var priorityName string // normal: id=3
4552

4653
for a := 0; a < len(argsWithoutProg); a++ {
4754
if argsWithoutProg[a] == "--type" {
@@ -61,6 +68,18 @@ func main() {
6168
if argsWithoutProg[a] == "--title" {
6269
pageTitle = argsWithoutProg[a+1]
6370
}
71+
if argsWithoutProg[a] == "--parent" {
72+
parent = argsWithoutProg[a+1]
73+
}
74+
if argsWithoutProg[a] == "--body" {
75+
body = argsWithoutProg[a+1]
76+
}
77+
if argsWithoutProg[a] == "--file" {
78+
file = argsWithoutProg[a+1]
79+
}
80+
if argsWithoutProg[a] == "--labels" {
81+
labels = argsWithoutProg[a+1]
82+
}
6483

6584
// jira
6685
if argsWithoutProg[a] == "--projKey" {
@@ -72,6 +91,9 @@ func main() {
7291
if argsWithoutProg[a] == "--priority" {
7392
priorityName = argsWithoutProg[a+1]
7493
}
94+
if argsWithoutProg[a] == "--descr" {
95+
description = argsWithoutProg[a+1]
96+
}
7597
}
7698

7799
tokService := token.TokenService{}
@@ -82,9 +104,16 @@ func main() {
82104
// Confluence instance
83105
switch instanceType {
84106
case "confluence":
107+
ps := serv.PageService{}
108+
ss := serv.SpaceService{}
109+
ls := serv.LabelService{}
110+
// find space's home page
111+
if pageTitle == "@home" {
112+
space := ss.GetSpace(url, anmaToken, spaceKey)
113+
pageTitle = space.Homepage.Title
114+
}
85115
switch action {
86116
case "getPage":
87-
ps := serv.PageService{}
88117
if pageId != "" {
89118
page := ps.GetPage(url, anmaToken, pageId)
90119
printPage(page)
@@ -93,9 +122,14 @@ func main() {
93122
printPage(page)
94123
}
95124
case "getSpace":
96-
ss := serv.SpaceService{}
97125
space := ss.GetSpace(url, anmaToken, spaceKey)
98126
fmt.Println(space)
127+
case "createPage":
128+
created := ps.CreateContent(url, anmaToken, "page", spaceKey, parent, pageTitle, body)
129+
if labels != "" {
130+
ls.AddLabels(url, anmaToken, created.Id, strings.Split(labels, ","))
131+
}
132+
printPage(created)
99133
}
100134

101135
// Jira instance
@@ -126,6 +160,7 @@ func main() {
126160
}
127161

128162
}
163+
log.Println(file) // todo
129164

130165
// == END
131166
fmt.Printf("Operations took '%f' secs", time.Now().Sub(start).Seconds())

readme.md

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,150 @@ https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/
55
- Groovy version - https://github.com/AndriiMaliuta/confluence-rest-service-groovy
66
- Rust version - https://github.com/AndriiMaliuta/rust-atlas-rest
77

8-
## Examples
8+
# Native CLI app
99

1010
### Confluence
1111
```bash
1212
./atlas --type confluence --action getPage --id "854950177"
1313
./atlas --type confluence --action getPage --space "TEST" --title "Page A"
1414
./atlas --type confluence --action getSpace --space "TEST"
15-
1615
```
1716

1817
### Jira
1918
```bash
20-
./atlas --type confluence --action getIssue --key "AAA-3"
21-
```
19+
./atlas --type jira --action getIssue --key "AAA-3"
20+
./atlas --type jira --action createIssue --summary "" --description "" --project ""
21+
```
22+
23+
24+
25+
## Internal API examples
26+
get services
27+
```
28+
grpcurl -plaintext localhost:9093 list
29+
```
30+
31+
### Pages
32+
getPage
33+
```curl
34+
./grpcurl -d '{"id": "123123"}' -plaintext localhost:50051 andmal.PageService.GetPage
35+
```
36+
37+
Create 20 pages
38+
```go
39+
for i := 2; i <= 20; i++ {
40+
space := spaceServ.GetSpace(cloudDcUrl, lToken, "TEST")
41+
pageServ.CreateContent(cloudDcUrl, lToken, "page", space.Key, space.Homepage.Id,
42+
fmt.Sprintf("GO page %d", i),
43+
ranServ.RandomString(100))
44+
}
45+
```
46+
47+
```go
48+
// === ASYNC == several
49+
var waitG sync.WaitGroup
50+
for i := 11; i <= 30; i++ {
51+
waitG.Add(1)
52+
bod := ranServ.RandomString(100)
53+
go func(count int) {
54+
space := spaceServ.GetSpace(cloudDcUrl, dcToken, "DEV15")
55+
pageServ.CreateContent(cloudDcUrl, dcToken, "page", space.Key, space.Homepage.Id,
56+
fmt.Sprintf("GO page %d", count), bod)
57+
}(i)
58+
}
59+
waitG.Wait()
60+
```
61+
62+
```go
63+
// ========== Get Page
64+
fmt.Println(pageServ.GetPage(cloudDcUrl, lToken, "98383"))
65+
66+
========== Create Page
67+
space := spaceServ.GetSpace(locUrl, lToken, "BBB")
68+
pageServ.CreateContent(locUrl, lToken, "page", space.Key, space.Homepage.Id, "GO page 1",
69+
ranServ.RandomString(100))
70+
```
71+
72+
Create space(s)
73+
```go
74+
fmt.Println(spaceServ.CreateSpace(locUrl, lToken, "DEV2", "DEV2"))
75+
76+
for i := 3; i < 20; i++ {
77+
fmt.Println(spaceServ.CreateSpace(locUrl, lToken, fmt.Sprintf("DEV%d", i), fmt.Sprintf("DEV%d", i)))
78+
}
79+
80+
// Operations took '124.458869' secs
81+
for a := 3; a <= 20; a++ {
82+
//wg.Add(1)
83+
go func() {
84+
key := fmt.Sprintf("DEV%d", a)
85+
sp := spaceServ.GetSpace(locUrl, lToken, key)
86+
for i := 40; i < 45; i++ {
87+
bod := ranServ.RandomString(15)
88+
pageServ.CreateContentAsync(locUrl, lToken, "page",
89+
sp.Key,
90+
sp.Homepage.Id,
91+
fmt.Sprintf("RST - %d", i), bod)
92+
}
93+
}()
94+
95+
fmt.Println(spaceServ.CreateSpace(locUrl, lToken, fmt.Sprintf("DEV%d", a), fmt.Sprintf("DEV%d", a)))
96+
}
97+
```
98+
99+
COMPLEX HIERARCHY
100+
```go
101+
var count int
102+
for i := 40; i <= 50; i++ {
103+
space := spaceServ.GetSpace(locUrl, lToken, fmt.Sprintf("test%d", i))
104+
homePage := space.Homepage
105+
for i := 1; i <= 100; i++ {
106+
bod := ranServ.RandomString(100)
107+
pageServ.CreateContent(locUrl, lToken, "page", space.Key, homePage.Id, fmt.Sprintf("%s - %d", homePage.Title, i), bod)
108+
}
109+
count += i
110+
}
111+
112+
log.Printf("%d pages created", count)
113+
114+
// === GET space
115+
//fmt.Println(spaceServ.GetSpace(locUrl, lToken, "DEV"))
116+
117+
// == Edit Page
118+
fmt.Println(pageServ.UpdatePage(locUrl, lToken, "2719745", "lorem", "lorem lorem lorem"))
119+
120+
// == COPY page
121+
pageServ.CopyPage(locUrl, lToken, "65603", "2326554", true, true, false)
122+
123+
// == COPY Hierarchy
124+
log.Println(pageServ.CopyPageDescs(bhtUrl, bhToken, "", "", "", true, true, false))
125+
126+
// ==== ADD attach
127+
for _, att := range pageServ.GetPageAttaches(locUrl, lToken, "2719753").Results {
128+
fmt.Println(att.Id)
129+
pageServ.CopyAttach(locUrl, lToken, "2981909", att.Id)
130+
}
131+
132+
// ==== Get attaches
133+
fmt.Println(pageServ.GetPageAttaches(locUrl, 1474565))
134+
135+
// === GET attach
136+
fmt.Println(pageServ.GetAttach(locUrl, 1671169))
137+
138+
// === Download attach
139+
pageServ.DownloadAttach(locUrl, 1671171)
140+
141+
142+
143+
// === Comments
144+
pageServ.AddComment(locUrl, lToken, "2555915", "2555911")
145+
```
146+
147+
### Labels
148+
```go
149+
fmt.Println(labServ.GetPageLabels(locUrl, lToken, "2719745"))
150+
151+
// ===== COPY labels
152+
labels := []string{"aaa", "bbb"}
153+
labServ.AddLabels(locUrl, lToken, "2555907", labels)
154+
```

run.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
./atlas --type confluence --action getPage --id "854950177"
44
./atlas --type confluence --action getPage --space "TEST" --title "Page A"
55
./atlas --type confluence --action getSpace --space "TEST"
6+
./atlas --type confluence --action createPage --title "p1" --space "TEST" --body "lorem" --parent "136445988"
7+
# create page with labels 'aa', 'bb'
8+
./atlas --type confluence --action createPage --title "p1" --space "TEST" --body "lorem" --parent "136445988" --labels "aa,bb"
9+
./atlas --type confluence --action copyPage --id "" --newTitle "" --parent "136445988"
610

711
# Jira
8-
./atlas --type confluence --action getIssue --key "AAA-3"
12+
./atlas --type jira --action getIssue --key "AAA-3"
13+
./atlas --type jira --action getProject --name "AAA"
14+
./atlas --type jira --action createIssue --summary "some" --descr "" --project "AAA"

0 commit comments

Comments
 (0)