Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ build: clean
# Create extension package
mkdir -p build/
gnome-extensions pack -f \
--extra-source=avatarLoader.js \
--extra-source=metadata.json \
--extra-source=LICENSE \
--extra-source=README.md \
Expand Down
2 changes: 2 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class GitLabIssuesIndicator extends PanelMenu.Button {
try {
if (message.status_code === 201 || message.status_code === 200) {
Main.notify(this._('GitLab Issues Timer'), `${this._('Time sent')}: ${duration} ${this._('on issue')} #${this._selectedIssue.iid}`);
} else if (message.status_code === 401 || message.status_code === 403) {
Main.notify(this._('Error'), this._('Please configure the server URL and token in preferences'));
} else {
Main.notify(this._('Error'), `${this._('Unable to send time')}: ${message.status_code}`);
}
Expand Down
90 changes: 62 additions & 28 deletions issueSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,64 @@ class IssueSelectorDialog extends ModalDialog.ModalDialog {
_loadProjects() {
this._showLoading(this._('Loading projects...'));

const url = this._settings.get_string('gitlab-url');
const token = this._settings.get_string('gitlab-token');

const apiUrl = `${url}/api/v4/projects?membership=true&per_page=100&order_by=last_activity_at`;

const message = Soup.Message.new('GET', apiUrl);
message.request_headers.append('PRIVATE-TOKEN', token);

this._httpSession.send_and_read_async(
message,
GLib.PRIORITY_DEFAULT,
null,
(session, result) => {
try {
const bytes = session.send_and_read_finish(result);
const decoder = new TextDecoder('utf-8');
const response = decoder.decode(bytes.get_data());

if (message.status_code === 200) {
this._projects = JSON.parse(response);
this._updateProjectList();
this._hideLoading();
} else {
this._showLoading(`${this._('Error')}: ${message.status_code}`);
try {
const url = this._settings.get_string('gitlab-url');
const token = this._settings.get_string('gitlab-token');

log(`GitLab Issue Selector: Fetching projects from URL: ${url}`);
log(`GitLab Issue Selector: Using token length: ${token ? token.length : 0}`);

const apiUrl = `${url}/api/v4/projects?membership=true&per_page=100&order_by=last_activity_at`;

const message = Soup.Message.new('GET', apiUrl);
message.request_headers.append('PRIVATE-TOKEN', token);

this._httpSession.send_and_read_async(
message,
GLib.PRIORITY_DEFAULT,
null,
(session, result) => {
let response = '';
try {
const bytes = session.send_and_read_finish(result);
const decoder = new TextDecoder('utf-8');
response = decoder.decode(bytes.get_data());

log(`GitLab Issue Selector: API response status code: ${message.status_code}`);
log(`GitLab Issue Selector: API response length: ${response.length}`);

if (message.status_code === 200) {
log('GitLab Issue Selector: Parsing projects JSON...');
this._projects = JSON.parse(response);
log(`GitLab Issue Selector: Loaded ${this._projects.length} projects`);
this._updateProjectList();
this._hideLoading();
} else if (message.status_code === 401 || message.status_code === 403) {
const authMessage = this._('Please configure the server URL and token in preferences');
this._projects = [];
this._updateProjectList();
this._showLoading(authMessage);
Main.notify(this._('Error'), authMessage);
} else {
log(`GitLab Issue Selector: Error fetching projects: ${message.status_code}`);
log(`GitLab Issue Selector: Response body: ${response}`);
this._showLoading(`${this._('Error')}: ${message.status_code}`);
}
} catch (e) {
log(`GitLab Issue Selector: Error parsing projects: ${e.message}`);
log(`GitLab Issue Selector: Full error: ${e.stack}`);
if (response) {
log(`GitLab Issue Selector: Response: ${response}`);
}
this._showLoading(`${this._('Error')}: ${e.message}`);
}
} catch (e) {
this._showLoading(`${this._('Error')}: ${e.message}`);
}
}
);
);
} catch (e) {
log(`GitLab Issue Selector: Error loading projects: ${e.message}`);
log(`GitLab Issue Selector: Full error: ${e.stack}`);
this._showLoading(`${this._('Error')}: ${e.message}`);
}
}

_updateProjectList() {
Expand Down Expand Up @@ -284,6 +312,12 @@ class IssueSelectorDialog extends ModalDialog.ModalDialog {
this._allIssues = JSON.parse(response);
this._updateIssueList();
this._hideLoading();
} else if (message.status_code === 401 || message.status_code === 403) {
const authMessage = this._('Please configure the server URL and token in preferences');
this._allIssues = [];
this._updateIssueList();
this._showLoading(authMessage);
Main.notify(this._('Error'), authMessage);
} else {
this._showLoading(`${this._('Error')}: ${message.status_code}`);
}
Expand Down
7 changes: 7 additions & 0 deletions reportDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class ReportDialog extends ModalDialog.ModalDialog {
this._selectProject(project, null);
}
}
} else if (message.status_code === 401 || message.status_code === 403) {
const authMessage = this._('Please configure the server URL and token in preferences');
this._projects = [];
Main.notify(this._('Error'), authMessage);
} else {
Main.notify(this._('Error'), `${this._('Unable to load projects')}: ${message.status_code}`);
}
Expand Down Expand Up @@ -448,6 +452,9 @@ class ReportDialog extends ModalDialog.ModalDialog {
if (message.status_code === 200) {
const issues = JSON.parse(response);
this._processReportData(issues);
} else if (message.status_code === 401 || message.status_code === 403) {
this._hideLoading();
Main.notify(this._('Error'), this._('Please configure the server URL and token in preferences'));
} else {
this._hideLoading();
Main.notify(this._('Error'), `${this._('Unable to load report')}: ${message.status_code}`);
Expand Down