-
Notifications
You must be signed in to change notification settings - Fork 7
/
gitea.js
79 lines (65 loc) · 2.46 KB
/
gitea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: MIT
import GLib from 'gi://GLib';
import { gettext as _ } from 'gettext';
import Forge from './forge.js';
import GitHub from './github.js';
import { session } from './../util.js';
/**
* Gitea implementation
*
* Gitea has a GitHub compatible API, so we can basically just derive from our
* GitHub class and tweak some mothods.
*/
export default class Gitea extends GitHub {
static name = 'gitea';
static prettyName = 'Gitea';
static allowInstances = true;
static defaultURL = 'gitea.com';
static get tokenText() {
/* Gitea access token help */
let tokenText = _('To generate a new access token from your instance, go to Settings → Applications and generate a new token.');
tokenText += '\n\n';
/* Gitea access token help */
tokenText += _('Forge Sparks requires the <i>read:issue</i>, <i>write:notification</i> and <i>read:user</i> scopes granted.');
return tokenText;
}
async markAsRead(id = null) {
/**
* Gitea differs from GitHub's markAsRead, params are url queries
*/
try {
if (id != null) {
const url = this.buildURI(`/notifications/threads/${id}`);
const message = super.createMessage('PATCH', url);
await session.send_and_read_async(message, GLib.PRIORITY_DEFAULT, null);
/* If Reset-Content */
return message.get_status() == '205';
} else {
const now = GLib.DateTime.new_now_utc();
const url = this.buildURI('notifications', {
'last_read_at': now.format_iso8601(),
'all': true
});
const message = super.createMessage('PUT', url);
await session.send_and_read_async(message, GLib.PRIORITY_DEFAULT, null);
/* If Reset-Content */
return message.get_status() == '205';
}
} catch (e) {
throw e;
}
}
/**
* Build a request URI from multiple parts
*
* This is a simplified version of Forge.buildURI with passed instance url
* set as host and api v1 prepended to path
*
* @param {String} path The URI path
* @param {Object.<string, string>} query The URI query
* @returns {String} The resulting URI
*/
buildURI(path, query = {}) {
return Forge.buildURI(this.url, '/api/v1/' + path, query);
}
};