Skip to content

Commit e928527

Browse files
refactor: add new utility function to prefill issue template and use it for link confirmation, part of #430
1 parent 5b3ed4e commit e928527

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

.github/ISSUE_TEMPLATE/link.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ body:
1616
label: Target
1717
validations:
1818
required: true
19+
- type: textarea
20+
id: sparql
21+
attributes:
22+
label: SPARQL query

js/browser/util.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ export function createGitHubIssue(repo: string, title: string, body: string, ass
5454
window.open(`${repo}/issues/new?title=${encodeURIComponent(title)}&body=${encodedBody}&assignees=${assignee}&labels=${label}`);
5555
}
5656

57+
/**
58+
/** Open a new issue on the GitHub repository using the given template.
59+
* @param repo - GIT repository URL
60+
* @param title - issue title
61+
* @param template - template filename without the .yml extension
62+
* @param fields - form field keys and string values
63+
*/
64+
export function createGitHubTemplateIssue(repo: string, title: string, template: string, fields: [string, string][]): void {
65+
const encodedFields = fields.map(([key, value]) => `&${key}=${encodeURIComponent(value)}`).reduce((a, b) => a + b);
66+
window.open(`${repo}/issues/new?template=${template}.yml&title=${encodeURIComponent(title)}${encodedFields}`);
67+
}
68+
5769
/**
5870
* Prompts creation of an issue on GitHub with the label specified in `config.git.issueLabels.deleteNode` and the default assignee to remove the given node.
5971
* @param node The node which is to be removed
@@ -109,22 +121,22 @@ ${language.CONSTANTS.SPARUL_WARNING}`;
109121
*/
110122
export function createGitHubConfirmLinkIssue(edge: EdgeSingular) {
111123
edge.data(EDGE.GRAPH, "http://www.snik.eu/ontology/match");
112-
const body = `Please confirm the automatic interlink ${edgeLabel(edge)}:
124+
const source = edge.data(EDGE.SOURCE);
125+
const target = edge.data(EDGE.TARGET);
126+
const property = edge.data(EDGE.PROPERTY);
127+
const triple = `{<${source}> <${property}> <${target}>.}`;
128+
const sparql = `Confirm on the SPARQL endpoint via:
113129
\`\`\`sparql
114-
DELETE DATA FROM <http://www.snik.eu/ontology/limes-exact>
115-
{<${edge.data(EDGE.SOURCE)}> <${edge.data(EDGE.PROPERTY)}> <${edge.data(EDGE.TARGET)}>.}
116-
INSERT DATA INTO <http://www.snik.eu/ontology/match>
117-
{<${edge.data(EDGE.SOURCE)}> <${edge.data(EDGE.PROPERTY)}> <${edge.data(EDGE.TARGET)}>.}
130+
DELETE DATA FROM <http://www.snik.eu/ontology/limes-exact> ${triple}
131+
INSERT DATA INTO <http://www.snik.eu/ontology/match> ${triple}
118132
\`\`\`\n
119133
Undo with
120134
\`\`\`sparql
121-
DELETE DATA FROM <http://www.snik.eu/ontology/match>
122-
{<${edge.data(EDGE.SOURCE)}> <${edge.data(EDGE.PROPERTY)}> <${edge.data(EDGE.TARGET)}>.}
123-
INSERT DATA INTO <http://www.snik.eu/ontology/limes-exact>
124-
{<${edge.data(EDGE.SOURCE)}> <${edge.data(EDGE.PROPERTY)}> <${edge.data(EDGE.TARGET)}>.}
135+
DELETE DATA FROM <http://www.snik.eu/ontology/match> ${triple}
136+
INSERT DATA INTO <http://www.snik.eu/ontology/limes-exact> ${triple}
125137
\n\`\`\`\n
126138
${language.CONSTANTS.SPARUL_WARNING}`;
127-
createGitHubIssue(config.git.repo.ontology, edgeLabel(edge), body, undefined, config.git.issueLabels.confirmLink);
139+
createGitHubTemplateIssue(config.git.repo.application, "Confirm " + edgeLabel(edge), "link", Object.entries({ source, target, sparql }));
128140
}
129141

130142
/** Creates a human readable string of the triple that an edge represents.

0 commit comments

Comments
 (0)