diff --git a/integration/__init__.py b/integration/__init__.py index e69de29..7d2a576 100644 --- a/integration/__init__.py +++ b/integration/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/integration/__main__.py b/integration/__main__.py index 23bf4ea..c2ffd00 100644 --- a/integration/__main__.py +++ b/integration/__main__.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + import argparse from .cli import Cli diff --git a/integration/ci.sh b/integration/ci.sh index 0552978..b523b58 100755 --- a/integration/ci.sh +++ b/integration/ci.sh @@ -1,5 +1,9 @@ #!/bin/bash +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + set -Exeuo pipefail source integration/lib.sh diff --git a/integration/cli.py b/integration/cli.py index 728fe6a..f3334e0 100644 --- a/integration/cli.py +++ b/integration/cli.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + import argparse from requests import Session diff --git a/integration/conf/app.ini b/integration/conf/app.ini index 3288db8..a48b049 100644 --- a/integration/conf/app.ini +++ b/integration/conf/app.ini @@ -1,3 +1,7 @@ +; SPDX-FileCopyrightText: 2023 Aravinth Manivannan +; +; SPDX-License-Identifier: AGPL-3.0-or-later + APP_NAME = Forgejo:+Beyond+Coding+We+Forge RUN_USER = git RUN_MODE = prod diff --git a/integration/csrf.py b/integration/csrf.py index 8d95d12..b5ff144 100644 --- a/integration/csrf.py +++ b/integration/csrf.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + from html.parser import HTMLParser diff --git a/integration/forgejo.py b/integration/forgejo.py index 0bfa38b..9c707b3 100755 --- a/integration/forgejo.py +++ b/integration/forgejo.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + import os import random import json diff --git a/integration/lib.sh b/integration/lib.sh index 7baf421..ccd3876 100755 --- a/integration/lib.sh +++ b/integration/lib.sh @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + is_ci(){ if [ -z ${CI+x} ]; then diff --git a/integration/tests.sh b/integration/tests.sh index 594ab4d..bd9b068 100755 --- a/integration/tests.sh +++ b/integration/tests.sh @@ -1,5 +1,9 @@ #!/bin/bash +# SPDX-FileCopyrightText: 2023 Aravinth Manivannan +# +# SPDX-License-Identifier: AGPL-3.0-or-later + set -Exeuo pipefail source integration/lib.sh diff --git a/src/api.ts b/src/api.ts deleted file mode 100644 index 77df56c..0000000 --- a/src/api.ts +++ /dev/null @@ -1,233 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Aravinth Manivannan -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -import Auth from "./auth"; -import User from "./spec/user"; -import Notification from "./spec/notification"; -import Issue from "./spec/issue"; -import Comment from "./spec/comments"; - -class Forgejo { - url: URL; - username: string; - token?: Auth; - /** - * Represents a Forgejo instance. - * @constructor - * @param {string} url - The URL of the Forgejo instance - * @param {string} username - username of the logged in user - */ - constructor(url: string, username: string) { - this.url = new URL(url); - this.username = username; - } - - /** - * Authenticate with token - * @param {Auth} token - access token - */ - setTokenAuth(token: string) { - this.token = new Auth(token); - } - - getTokenAuth(): Auth { - if (this.token) { - return this.token; - } else { - throw new Error("set authentication token before use"); - } - } - - getTokenAuthHeader() { - return { Authorization: `token ${this.getTokenAuth().getToken()}` }; - } - - /** - * Get logged in user - */ - async getUser(): Promise { - this.url.pathname = "/api/v1/user"; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - return await res.json(); - } - - /** - * Get all notifications - */ - async getNotifications(): Promise> { - this.url.pathname = "/api/v1/notifications"; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - - return await res.json(); - } - /** - * Get number of unread notifications - */ - async getNumUnreadNotifications(): Promise { - this.url.pathname = "/api/v1/notifications/new"; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - - let data = await res.json(); - return data["new"]; - } - - /** - * Get Notification Thread - * @param {number} id - The ID of a notification thread - */ - async getNotificationThread(id: number): Promise { - this.url.pathname = `/api/v1/notifications/threads/${id}`; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - return await res.json(); - } - - /** - * Get the time at which the issue was last read - */ - lastReadTime(issue: Issue): Date { - return new Date("01/01/01"); // TODO: return last read time from storage. If unread, return 0 - } - - /** - * Check if logged in user is mentioned in the issue - */ - async findMentionsInIssue(owner: string, repo: string, id: number) { - let issue = await this.getIssue(owner, repo, id); - issue = await this.getCommentsForIssue(issue); - let unreadTime = this.lastReadTime(issue); - - const mentionUtil = (str: string): boolean => { - return str.includes(this.username); - }; - - const items = []; - - if (new Date(issue.created_at) > unreadTime) { - items.push(issue.title); - items.push(issue.body); - } - - issue.lazy_comments_data.forEach((comment) => { - if (comment.created_at > unreadTime) { - items.push(comment.body); - return; - } - if (comment.updated_at) { - if (comment.updated_at > unreadTime) { - items.push(comment.body); - return; - } - } - }); - - let mention = false; - items.forEach((item) => { - if (mentionUtil(item)) { - mention = true; - return; - } - }); - return mention; - } - - /** - * Mark Notification Read - * @param {number} id - The ID of a notification thread - */ - async markNotificationRead(id: number) { - this.url.pathname = `/api/v1/notifications/threads/${id}`; - await fetch(this.url, { method: "PATCH" }); - } - - /** - * Mark Notification Read for a specific repository - * @param {string} owner - Name of the owner of the repository - * @param {string} repo - Name of the repository - */ - async markNotificationReadForRepo(owner: string, repo: string) { - this.url.pathname = `/api/v1/repos/${owner}/${repo}/notifications`; - await fetch(this.url, { method: "PUT" }); - } - - /** - * Get Issue and its comments - * @param {str} owner - The owner of the repository - * @param {str} repo - The name of the repository - * @param {number} id - The ID of an issue - */ - async getIssue(owner: string, repo: string, id: number): Promise { - this.url.pathname = `/api/v1/repos/${owner}/${repo}/issues/${id}`; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - let issue = await res.json(); - - if (typeof issue.created_at === "string") { - issue.created_at = new Date(issue.created_at); - } - - if (issue.updated_at) { - if (typeof issue.updated_at === "string") { - issue.updated_at = new Date(issue.updated_at); - } - } - - if (issue.closed_at) { - if (typeof issue.closed_at === "string") { - issue.closed_at = new Date(issue.closed_at); - } - } - - return issue; - } - - async getCommentsForIssue(issue: Issue): Promise { - // TODO: check if issue.number != issue.id causes problems. I'm assuming - // Issue.number is the local repository issue ID and issue.id is DB ID - this.url.pathname = `/api/v1/repos/${issue.repository.owner}/${issue.repository.name}/issues/${issue.number}/comments`; - let res = await fetch(this.url, { - method: "GET", - credentials: "include", - headers: this.getTokenAuthHeader(), - }); - let c: Array = await res.json(); - - c = c.map((comment) => { - if (typeof comment.created_at === "string") { - comment.created_at = new Date(comment.created_at); - } - - if (comment.updated_at) { - if (typeof comment.updated_at === "string") { - comment.updated_at = new Date(comment.updated_at); - } - } - return comment; - }); - - issue.lazy_comments_data = c; - - return issue; - } -} - -export default Forgejo; diff --git a/src/auth.ts b/src/auth.ts index d05ff95..2108c25 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + class Auth { token: string; constructor(token: string) { diff --git a/src/spec/comments.ts b/src/spec/comments.ts index c545b04..5fab9e6 100644 --- a/src/spec/comments.ts +++ b/src/spec/comments.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + import User from "./user"; type Comment = { diff --git a/src/spec/issue.ts b/src/spec/issue.ts index cccc1fd..50db36b 100644 --- a/src/spec/issue.ts +++ b/src/spec/issue.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + import User from "./user"; import Comment from "./comments"; diff --git a/src/spec/notification.ts b/src/spec/notification.ts index fd6df05..db324e1 100644 --- a/src/spec/notification.ts +++ b/src/spec/notification.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + import Repository from "./repository"; type Subject = { diff --git a/src/spec/owner.ts b/src/spec/owner.ts deleted file mode 100644 index b5755f5..0000000 --- a/src/spec/owner.ts +++ /dev/null @@ -1,8 +0,0 @@ -type Repository = { - id: number; - name: string; - full_name: string; - html_url: string; -}; - -export default Repository; diff --git a/src/spec/repository.ts b/src/spec/repository.ts index 1f63132..1da857c 100644 --- a/src/spec/repository.ts +++ b/src/spec/repository.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + import User from "./user"; type Repository = { diff --git a/src/spec/user.ts b/src/spec/user.ts index df6a8e9..4a89d0a 100644 --- a/src/spec/user.ts +++ b/src/spec/user.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + type User = { id: number; login: string;