Skip to content

Commit 202df53

Browse files
fix(gitea): fix gitea integration (#2398)
* fix(gitea): fix integration selectors and add origins file reference * Update origins.js
1 parent ffb78e4 commit 202df53

File tree

2 files changed

+81
-22
lines changed

2 files changed

+81
-22
lines changed

src/content/gitea.js

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,95 @@
1-
'use strict';
1+
/**
2+
* @name Gitea
3+
* @urlAlias gitea.com
4+
* @urlRegex *://gitea.com/*
5+
*/
6+
'use strict'
27
/* global togglbutton, $ */
38

4-
togglbutton.render('.time-desc:not(.toggl)',
9+
togglbutton.render(
10+
'.time-desc:not(.toggl)',
511
{ observe: true },
6-
$container => {
12+
($container) => {
713
const link = togglbutton.createTimerLink({
814
className: 'gitea',
915
description: descriptionSelector,
1016
tags: tagsSelector,
1117
projectName: projectSelector,
12-
});
13-
$container.appendChild(link);
18+
})
19+
$container.appendChild(link)
20+
},
21+
)
22+
23+
function descriptionSelector() {
24+
const description = document.getElementById('issue-title-display')
25+
if (!description) {
26+
return ''
27+
}
28+
29+
const h1 = description.querySelector('h1')
30+
if (!h1) {
31+
return description.textContent.trim()
1432
}
15-
);
1633

17-
function descriptionSelector () {
18-
const description = document.getElementById('issue-title');
19-
const issueId = description.nextElementSibling;
20-
return `${issueId.textContent.trim()} ${description.textContent.trim()}`;
34+
let textContent = ''
35+
for (const node of h1.childNodes) {
36+
if (node.nodeType === Node.TEXT_NODE) {
37+
textContent += node.textContent
38+
}
39+
}
40+
41+
return textContent.trim()
2142
}
2243

23-
function projectSelector () {
24-
const $project = document.getElementsByClassName('repo-title')[0].children[3];
25-
return $project ? $project.textContent.trim() : '';
44+
function projectSelector() {
45+
const issueContentRight = document.getElementsByClassName(
46+
'issue-content-right',
47+
)
48+
if (!issueContentRight || issueContentRight.length === 0) {
49+
return ''
50+
}
51+
52+
const projectsSection = issueContentRight[0].querySelector(
53+
'[data-update-url*="projects"]',
54+
)
55+
if (!projectsSection) {
56+
return ''
57+
}
58+
59+
const selectedProject = projectsSection.querySelector('a.item.muted.checked')
60+
if (!selectedProject) {
61+
return ''
62+
}
63+
64+
return selectedProject.textContent.trim()
2665
}
2766

28-
function tagsSelector () {
29-
const $tags = document.getElementsByClassName('labels-list')[0].children;
30-
var $result = [];
31-
for (var element of $tags) {
32-
if (element.children.length > 0 && !element.children[0].classList.contains("hide")) {
33-
$result.push(element.children[0].textContent.trim());
67+
function tagsSelector() {
68+
const issueContentRight = document.getElementsByClassName(
69+
'issue-content-right',
70+
)[0]
71+
if (!issueContentRight) {
72+
return []
73+
}
74+
75+
const labelsList = issueContentRight.getElementsByClassName('labels-list')[0]
76+
if (!labelsList) {
77+
return []
78+
}
79+
80+
const $result = []
81+
const labelLinks = labelsList.querySelectorAll('a.item')
82+
83+
for (const labelLink of labelLinks) {
84+
const labelSpan = labelLink.querySelector('span.ui.label')
85+
if (labelSpan) {
86+
const labelText = labelSpan.querySelector('span.gt-ellipsis')
87+
if (labelText) {
88+
const text = labelText.textContent.trim()
89+
$result.push(text)
90+
}
3491
}
3592
}
36-
return $result;
93+
94+
return $result
3795
}

src/origins.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default {
217217
name: 'Freshdesk'
218218
},
219219
'freshservice.com': {
220-
url: '^https?://.*\.freshservice\.com',
220+
url: '^https?://.*.freshservice.com',
221221
name: 'Freshservice',
222222
file: 'freshservice.js'
223223
},
@@ -235,7 +235,8 @@ export default {
235235
},
236236
'gitea.com': {
237237
url: '*://gitea.com/*',
238-
name: 'Gitea'
238+
name: 'Gitea',
239+
file: 'gitea.js'
239240
},
240241
'github.com': {
241242
url: '*://github.com/*',

0 commit comments

Comments
 (0)