Skip to content

Commit

Permalink
Added settings for group level, and project level. Added option for p…
Browse files Browse the repository at this point in the history
…urgingIssues everytime, or not. Fix gitlab PAT reloading plugin. Fix gitlab icon. (#23)

Co-authored-by: Jonathan Deates <[email protected]>
  • Loading branch information
JonnyDeates and Jonathan Deates authored Jan 30, 2024
1 parent fa00ea1 commit 25052b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/assets/gitlab-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions src/gitlab-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ export default class GitlabLoader {
this.settings = settings;
}

getUrl() {
switch (this.settings.gitlabIssuesLevel) {
case "project":
return `${this.settings.gitlabApiUrl()}/projects/${this.settings.gitlabAppId}/issues?${this.settings.filter}`;
case "group":
return `${this.settings.gitlabApiUrl()}/groups/${this.settings.gitlabAppId}/issues?${this.settings.filter}`;
case "personal":
default:
return `${this.settings.gitlabApiUrl()}/issues?${this.settings.filter}`;
}
}

loadIssues() {
// URL Encode the user filter settings
const apiURL = `${this.settings.gitlabApiUrl()}/issues?${this.settings.filter}`;
GitlabApi.load<Array<Issue>>(encodeURI(apiURL), this.settings.gitlabToken)
GitlabApi.load<Array<Issue>>(encodeURI(this.getUrl()), this.settings.gitlabToken)
.then((issues: Array<Issue>) => {
const gitlabIssues = issues.map((rawIssue: Issue) => new GitlabIssue(rawIssue));
this.fs.purgeExistingIssues();

if(this.settings.purgeIssues) {
this.fs.purgeExistingIssues();
}

this.fs.processIssues(gitlabIssues);
})
.catch(error => {
Expand Down
61 changes: 48 additions & 13 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import {App, PluginSettingTab, Setting, normalizePath} from "obsidian";
import {App, normalizePath, PluginSettingTab, Setting} from "obsidian";
import GitlabIssuesPlugin from "./main";

type GitlabIssuesLevel = 'personal' | 'project' | 'group'

export interface GitlabIssuesSettings {
gitlabUrl: string;
gitlabToken: string;
gitlabIssuesLevel: GitlabIssuesLevel;
gitlabAppId: string;
templateFile: string;
outputDir: string;
filter: string;
showIcon: boolean;
purgeIssues: boolean;
gitlabApiUrl(): string;
}

export const DEFAULT_SETTINGS: GitlabIssuesSettings = {
gitlabUrl: 'https://gitlab.com',
gitlabToken: '',
gitlabIssuesLevel: 'personal',
gitlabAppId: '',
templateFile: '',
outputDir: '/Gitlab Issues/',
filter: 'due_date=month',
showIcon: false,
purgeIssues: true,
gitlabApiUrl(): string {
return `${this.gitlabUrl}/api/v4`;
}
Expand All @@ -38,15 +46,15 @@ export class GitlabIssuesSettingTab extends PluginSettingTab {
containerEl.createEl('h2', {text: 'GitLab Issues Configuration'});

new Setting(containerEl)
.setName('Gitlab instance URL')
.setDesc('Use your own Gitlab instance instead of the public hosted Gitlab.')
.addText(text => text
.setPlaceholder('https://gitlab.com')
.setValue(this.plugin.settings.gitlabUrl)
.onChange(async (value) => {
this.plugin.settings.gitlabUrl = value;
await this.plugin.saveSettings();
}));
.setName('Gitlab instance URL')
.setDesc('Use your own Gitlab instance instead of the public hosted Gitlab.')
.addText(text => text
.setPlaceholder('https://gitlab.com')
.setValue(this.plugin.settings.gitlabUrl)
.onChange(async (value) => {
this.plugin.settings.gitlabUrl = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Personal Access Token')
Expand All @@ -57,9 +65,6 @@ export class GitlabIssuesSettingTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.gitlabToken = value;
await this.plugin.saveSettings();
this.plugin.onload().then(
() => console.log('Gitlab Issues: Reloading plugin')
);
}));

new Setting(containerEl)
Expand Down Expand Up @@ -96,6 +101,36 @@ export class GitlabIssuesSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));


new Setting(containerEl)
.setName('GitLab Level')
.addDropdown(value => value
.addOptions({personal: "Personal", project: "Project", group: "Group"})
.setValue(this.plugin.settings.gitlabIssuesLevel)
.onChange(async (value: GitlabIssuesLevel) => {
this.plugin.settings.gitlabIssuesLevel = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Set Gitlab Project/Group Id')
.setDesc('If Group or Project is set, add the corresponding ID.')
.addText(value => value
.setValue(this.plugin.settings.gitlabAppId)
.onChange(async (value: string) => {
this.plugin.settings.gitlabAppId = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Purge issues that are no longer in Gitlab?')
.addToggle(value => value
.setValue(this.plugin.settings.purgeIssues)
.onChange(async (value) => {
this.plugin.settings.purgeIssues = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Show refresh Gitlab issues icon in left ribbon?')
.addToggle(value => value
Expand Down

0 comments on commit 25052b1

Please sign in to comment.