Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GitLab API finder error handling #569

Merged
merged 3 commits into from
May 31, 2021
Merged
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
17 changes: 12 additions & 5 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Gitlab {
}

async repoBase() {
if (this._detected_base) return this._detected_base;
if (this.detectedBase) return this.detectedBase;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could still keep the underscore prefix though if the intention was to be a private var.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More conventional than anything else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most idiomatic alternative would be using a private field, but that's just a proposal.

Copy link
Member Author

@0x2b3bfa0 0x2b3bfa0 May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use that variable to memoi*e the function result, so it can be considered private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not have to be private either but should be exposed in other drivers for consisitency, being very purist we should do a closure of request here with the detectedbase... not needed IMHO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a closure sounds tempting, but would add a considerable maintenance overhead and nobody cares about our internal API, yet. 😅 Let's leave it be for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casperdcl, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes not really massive priority to do this at enterprise level yet, fine as-is


const { origin, pathname } = new URL(this.repo);
const possibleBases = await Promise.all(
Expand All @@ -53,14 +53,21 @@ class Gitlab {
.version
)
return path;
} catch (error) {}
} catch (error) {
return error;
}
})
);

this._detected_base = possibleBases.find(Boolean);
if (!this._detected_base) throw new Error('GitLab API not found');
this.detectedBase = possibleBases.find(
(base) => base.constructor !== Error
);
if (!this.detectedBase) {
if (possibleBases.length) throw possibleBases[0];
throw new Error('Invalid repository address');
}

return this._detected_base;
return this.detectedBase;
}

async commentCreate(opts = {}) {
Expand Down