Skip to content

Commit 6acbe45

Browse files
authored
Merge pull request #2275 from HicServices/task/confluence-service-worker
Task/confluence service worker
2 parents bd1abfe + 8822be4 commit 6acbe45

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [9.1.1] - Unreleased
8+
- Allow Atlassian service workers to write to Confluence from RDMP
9+
710
## [9.1.0] - 2025-11-24
811
- Fix bug with duplicate searchables
912
- Improve UI for committing cohorts across projects

Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandExportCataloguesToConfluence.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class ExecuteCommandExportCataloguesToConfluence : BasicCommandExecution,
2222
private readonly string _apiKey;
2323
private readonly string _owner;
2424
private readonly string _description;
25+
private readonly bool _isServiceAccount;
26+
private readonly int? _rootPageParent;
2527
private readonly HttpClient _client = new();
2628
private readonly Dictionary<int, string> _cataloguePageLookups = [];
2729
private string rootParentId = null;
@@ -91,14 +93,16 @@ private class ConfluencePageResponse
9193
public ConfluencePageVersion version { get; set; }
9294
}
9395

94-
public ExecuteCommandExportCataloguesToConfluence(IBasicActivateItems activator, string subdomain, int spaceId, string apiKey, string owner, string description)
96+
public ExecuteCommandExportCataloguesToConfluence(IBasicActivateItems activator, string subdomain, int spaceId, string apiKey, string owner, string description, bool isServiceaccount, int? rootPageParent = null)
9597
{
9698
_activator = activator;
9799
_subdomain = subdomain;
98100
_spaceId = spaceId;
99101
_apiKey = apiKey;
100102
_owner = owner;
101103
_description = description;
104+
_isServiceAccount = isServiceaccount;
105+
_rootPageParent = rootPageParent;
102106
}
103107

104108
private static ConfluencePageResponse ResponseToConfluenceResponseObject(HttpResponseMessage response)
@@ -162,6 +166,10 @@ private void CreateContainerPage(ConfluencePageBuilder builder, string uri)
162166
title = $"{_owner} Catalogues",
163167
body = new ConfluencePageBody() { value = rootPageHTML }
164168
};
169+
if (_rootPageParent != null)
170+
{
171+
request.parentId = _rootPageParent.ToString() ;
172+
}
165173
HttpResponseMessage response = Task.Run(async () => await _client.PostAsJsonAsync(uri, request)).Result;
166174
if (response.StatusCode == System.Net.HttpStatusCode.OK)
167175
{
@@ -200,7 +208,7 @@ private void CreateCataloguePage(Catalogue catalogue, ConfluencePageBuilder buil
200208
var request = new ConfluencePagePostRequest()
201209
{
202210
spaceId = _spaceId.ToString(),
203-
title = catalogue.Name,
211+
title = $"{catalogue.Name}{(catalogue.Acronym != null ? $" ({catalogue.Acronym})" : "")}",
204212
parentId = rootParentId,
205213
body = new ConfluencePageBody() { value = cataloguePageHTML }
206214
};
@@ -256,8 +264,7 @@ public override void Execute()
256264
.Where(c => !c.IsDeprecated && !c.IsInternalDataset && !c.IsProjectSpecific(_activator.RepositoryLocator.DataExportRepository))
257265
.ToList();
258266
var builder = new ConfluencePageBuilder(catalogues, _owner, _description, _subdomain);
259-
var uri = $"https://{_subdomain}.atlassian.net/wiki/api/v2/pages";
260-
267+
var uri = _isServiceAccount ? $"https://api.atlassian.com/ex/confluence/{_subdomain}/api/v2/pages" : $"https://{_subdomain}.atlassian.net/wiki/api/v2/pages";
261268
CreateContainerPage(builder, uri);
262269
if (rootParentId != null)
263270
{

Rdmp.Core/Dataset/Confluence/ConfluencePageBuilder.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ public class ConfluencePageBuilder
1919
private readonly string _repositoryName = "";
2020
private readonly string _repositoryDescription = "";
2121
private readonly string _subdomain = "";
22-
public ConfluencePageBuilder(List<Catalogue> catalogues, string name,string description, string subdomain) {
22+
public ConfluencePageBuilder(List<Catalogue> catalogues, string name, string description, string subdomain)
23+
{
2324
_catalogues = catalogues;
2425
_repositoryName = name;
2526
_repositoryDescription = description;
2627
_subdomain = subdomain;
2728
}
2829

29-
private string BuildCatalogueOverviewHTML(Catalogue catalogue,string pageId)
30+
private string BuildCatalogueOverviewHTML(Catalogue catalogue, string pageId)
3031
{
3132
Console.WriteLine($"Building overview for catalogue '{catalogue.Name}'");
32-
string name = pageId != null ?$"<a href='https://{_subdomain}.atlassian.net/wiki/{pageId}'>{catalogue.Name}</a>" : catalogue.Name;
33+
string name = pageId != null ? $"<a href='https://{_subdomain}.atlassian.net/wiki{pageId}'>{catalogue.Name}</a>" : catalogue.Name;
3334

3435
return $"""
35-
<h2>{catalogue.Name}</h2>
36+
<h2>{catalogue.Name}{(catalogue.Acronym != null ? $" ({catalogue.Acronym})" : "")}</h2>
3637
<table>
3738
<tr>
3839
<th>
@@ -44,6 +45,9 @@ Dataset Name
4445
<th>
4546
Tags
4647
</th>
48+
<th>
49+
Acronym
50+
</th>
4751
</tr>
4852
<tr>
4953
<td>
@@ -53,21 +57,25 @@ Dataset Name
5357
{catalogue.Description}
5458
</td>
5559
<td>
56-
{string.Join(", ",catalogue.Search_keywords)}
60+
{string.Join(", ", catalogue.Search_keywords)}
61+
</td>
62+
<td>
63+
{catalogue.Acronym}
5764
</td>
5865
</tr>
5966
</table>
6067
""";
6168
}
6269

63-
public string BuildContainerPage(Dictionary<int, string> cataloguePageLookup) {
70+
public string BuildContainerPage(Dictionary<int, string> cataloguePageLookup)
71+
{
6472
Console.WriteLine($"Building container page. Found {_catalogues.Count} catalogues.");
6573
return $"""
6674
6775
<h2>{_repositoryName} Catalogues</h2>
6876
<p>{_repositoryDescription}</p>
6977
<p><ac:structured-macro ac:name='toc'/></p>
70-
{string.Join("",_catalogues.Select(c => { cataloguePageLookup.TryGetValue(c.ID, out var pageId); return BuildCatalogueOverviewHTML(c, pageId); }))}
78+
{string.Join("", _catalogues.Select(c => { cataloguePageLookup.TryGetValue(c.ID, out var pageId); return BuildCatalogueOverviewHTML(c, pageId); }))}
7179
""";
7280
}
7381

@@ -230,7 +238,7 @@ Null Possible (Y/N)
230238
Has Lookups
231239
</th>
232240
</tr>
233-
{string.Join("",catalogue.CatalogueItems.Where(ci => ci.ExtractionInformation is not null).Select(ci => BuildDataVariableRecord(ci)))}
241+
{string.Join("", catalogue.CatalogueItems.Where(ci => ci.ExtractionInformation is not null).Select(ci => BuildDataVariableRecord(ci)))}
234242
</table>
235243
""";
236244
}

0 commit comments

Comments
 (0)