Skip to content

Commit 4fe3ce8

Browse files
committed
修改判断confluence新内容和旧内容是否一样的相关代码
1 parent 256768a commit 4fe3ce8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

api_content.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ func (cli *Client) PageFindOrCreateBySpaceAndTitle(space, parentId, title, wikiD
163163
//因此前先去掉,以避免对比内容变化时受到影响
164164
data = strings.TrimSuffix(strings.TrimPrefix(data, "\n"), "\n")
165165

166+
//获取当前页面的内容
166167
content, err := cli.ContentBySpaceAndTitle(space, title)
167168
if err != nil {
168169
return Content{}, fmt.Errorf("查找%s出错: %s", title, err)
169170
}
170171

171172
// 不存在则创建
172173
if content.Id == "" {
174+
data += fmt.Sprintf(ConfluenceNoteMacro, extraInfo)
173175
return cli.PageCreateInSpace(space, parentId, title, data)
174176
}
175177

@@ -192,18 +194,22 @@ func (cli *Client) PageFindOrCreateBySpaceAndTitle(space, parentId, title, wikiD
192194
return Content{}, fmt.Errorf("转换新内容失败: %s", err)
193195
}
194196

197+
// 去除原文件的备注宏
198+
if content.Body.Storage.Value != "" {
199+
content.Body.Storage.Value = strings.Split(content.Body.Storage.Value, ConfluenceNoteSplite)[0]
200+
}
195201
oldValue, err := cli.ContentBodyConvertTo(content.Body.Storage.Value, "storage", "view")
196202
if err != nil {
197203
return Content{}, fmt.Errorf("转换旧内容失败: %s", err)
198204
}
199205

200206
if newValue == oldValue && lastAncestorId == parentId {
201207
return content, nil
208+
} else {
209+
// 如果确定要更新confluence页面,那么这里添加一个备注宏
210+
data += fmt.Sprintf(ConfluenceNoteMacro, extraInfo)
202211
}
203212

204-
// 如果确定要更新confluence页面,那么这里添加一个备注宏
205-
data += fmt.Sprintf(ConfluenceNoteMacro, extraInfo)
206-
207213
// 存在则否则更新
208214
content.Space.Key = space
209215
content.Version.Number += 1

constant.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package confluence
22

33
//Confluence的备注宏,用于备注git的信息
44
const ConfluenceNoteMacro = `
5+
<br />
6+
<br />
7+
<br />
8+
<hr />
59
<ac:structured-macro ac:name="note">
610
<ac:parameter ac:name="icon">true</ac:parameter>
711
<ac:parameter ac:name="title">Git提交信息</ac:parameter>
@@ -10,3 +14,10 @@ const ConfluenceNoteMacro = `
1014
</ac:rich-text-body>
1115
</ac:structured-macro>
1216
`
17+
18+
var ConfluenceNoteSplite = `
19+
<br />
20+
<br />
21+
<br />
22+
<hr />
23+
`

0 commit comments

Comments
 (0)