-
Notifications
You must be signed in to change notification settings - Fork 17
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
Added gitlab avatar support #56
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ var Person = new Lang.Class({ | |
this.tz = params.tz; | ||
this.avatar = params.avatar; | ||
this.github = params.github; | ||
this.gitlab = params.gitlab; | ||
this.gravatar = params.gravatar; | ||
this._githubToken = params._githubToken; | ||
|
||
|
@@ -40,6 +41,11 @@ var Person = new Lang.Class({ | |
return; | ||
} | ||
|
||
if (this.gitlab) { | ||
this._getGitLabInfo(); | ||
return; | ||
} | ||
|
||
if (this.gravatar) { | ||
this._getGravatarInfo(); | ||
return; | ||
|
@@ -80,6 +86,40 @@ var Person = new Lang.Class({ | |
})); | ||
}, | ||
|
||
_getGitLabInfo: function() { | ||
let _httpSession = new Soup.Session({user_agent: 'jwendell/gnome-shell-extension-timezone'}); | ||
let url = 'https://gitlab.com/api/v4/avatar?email=%s'.format(this.gitlab); | ||
let message = new Soup.Message({method: 'GET', uri: new Soup.URI(url)}); | ||
if (this._gitlabToken) { | ||
message.request_headers.append("Authorization", "token " + this._gitlabToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to https://docs.gitlab.com/ee/api/#oauth2-tokens should this header be |
||
} | ||
|
||
_httpSession.queue_message(message, Lang.bind(this, function(session, message) { | ||
if (message.status_code != Soup.KnownStatusCode.OK) { | ||
log('Response code "%d" getting data from gitlab for user email address %s. Got: %s'.format(message.status_code, this.github, message.response_body.data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return; | ||
} | ||
let p; | ||
try { | ||
p = JSON.parse(message.response_body.data); | ||
} catch (e) { | ||
log('Error parsing gitlab email address response for user %s: %s'.format(this.gitlab, e)); | ||
return; | ||
} | ||
|
||
if (!this.avatar && p.avatar_url) | ||
this.avatar = p.avatar_url; | ||
|
||
if (!this.name && p.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at https://docs.gitlab.com/ee/api/avatar.html it seems the |
||
this.name = p.name; | ||
|
||
if (!this.city && p.location) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
this.city = p.location; | ||
|
||
this.emit('changed'); | ||
})); | ||
}, | ||
|
||
_getGravatarInfo: function() { | ||
if (this.avatar) | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,10 @@ | |
"type": "string", | ||
"description": "Gravatar ID (person's email)" | ||
}, | ||
"gitlab": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps we could make |
||
"type": "string", | ||
"description": "GitLab avatar (person's email)" | ||
}, | ||
"github": { | ||
"type": "string", | ||
"description": "GitHub ID" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this field come from?