Skip to content

Commit

Permalink
Fix starred repos click event (#47)
Browse files Browse the repository at this point in the history
Click on starred repo opens repo's page when author is not the logged user. fixes #46
  • Loading branch information
barriosnahuel committed Apr 24, 2016
1 parent d2167e2 commit f935630
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 25 deletions.
12 changes: 6 additions & 6 deletions extension/js/bend/api/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ spk.lib = (function () {

var getEvents = function (callback) {

chrome.storage.sync.get('username', function (localStorage) {
if (localStorage.username) {
chrome.storage.sync.get('username', function (syncedStorage) {
if (syncedStorage.username) {

chrome.storage.local.get('accessToken', function (syncedStorage) {
chrome.storage.local.get('accessToken', function (localStorage) {

if (syncedStorage.accessToken) {
if (localStorage.accessToken) {
$.ajax({
url: 'https://api.github.com/users/' + localStorage.username + '/received_events',
url: 'https://api.github.com/users/' + syncedStorage.username + '/received_events',
beforeSend: function (jqXHR) {
jqXHR.setRequestHeader('Authorization', 'token ' + syncedStorage.accessToken);
jqXHR.setRequestHeader('Authorization', 'token ' + localStorage.accessToken);
}
}).done(function (data, textStatus, jqXHR) {
console.info('GitHub\'s API called OK');
Expand Down
6 changes: 3 additions & 3 deletions extension/js/bend/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ var spk = spk || {};
});
};

var processEvent = function (eachEvent) {
var dto = spk.events.manager.parse(eachEvent);
var processEvent = function (eachEvent, username) {
var dto = spk.events.manager.parse(eachEvent, username);
var notification;

if (dto && spk.events.manager.shouldProcess(dto)) {
Expand Down Expand Up @@ -209,7 +209,7 @@ var spk = spk || {};
for (var i = 0; i < mergedEvents.length; i++) {
var eachMergedEvent = mergedEvents[i];

var notification = processEvent(eachMergedEvent);
var notification = processEvent(eachMergedEvent, storage.username);
if (notification) {
notifications.push(notification);
}
Expand Down
20 changes: 13 additions & 7 deletions extension/js/bend/events/create_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ spk.events = spk.events || {};

spk.events.createEvent = (function () {

/**
* Generates the entire web page for a specific GitHub section.
* @param repo It should be the repo's owner and the repo name, like: "barriosnahuel/spokesman".
* @param section The target section, like "releases".
* @param branch You know what.
* @returns {string} i.e.: https://github.com/barriosnahuel/spokesman/tree/develop
*/
var buildRepoPage = function (repo, section, branch) {
return spk.properties.github_web + repo + '/' + section + '/' + branch;
};

var parseGitHubEvent = function (event) {
var result;

switch (event.payload.ref_type) {
case 'repository':
result = {
description: event.payload.description
, link: 'https://github.com/' + event.repo.name
, link: spk.properties.github_web + event.repo.name
};
break;
case 'tag':
result = {
branch: event.payload.ref
, link: 'https://github.com/' + event.repo.name + '/releases/' + event.payload.ref
};
break;
case 'branch':
result = {
branch: event.payload.ref
, link: 'https://github.com/' + event.repo.name + '/tree/' + event.payload.ref
, link: buildRepoPage(event.repo.name, event.payload.ref_type === 'tag' ? 'releases' : 'tree', event.payload.ref)
};
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion extension/js/bend/events/delete_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spk.events.deleteEvent = (function () {
return {
branch: event.payload.ref
, type: event.payload.ref_type
, link: 'https://github.com/' + event.repo.name + (event.payload.ref_type === 'tag' ? '/tags' : '/branches')
, link: spk.properties.github_web + event.repo.name + (event.payload.ref_type === 'tag' ? '/tags' : '/branches')
};
};

Expand Down
9 changes: 5 additions & 4 deletions extension/js/bend/events/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ spk.events.manager = (function () {
};

/**
* ToDo: Add documentation!!
* @param event
* Parse basic data required for any kind of event, and also parses each specific event's data by calling the manager.js.
* @param event The event to parse.
* @param username The login name of the configured user.
*/
var parse = function (event) {
var parse = function (event, username) {
var result;

var eventManager = findEvent(event.type);
if (eventManager) {
var payload = eventManager.parse(event);
var payload = eventManager.parse(event, username);

if (payload) {
var dto = parseBasicData(event);
Expand Down
2 changes: 1 addition & 1 deletion extension/js/bend/events/push_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spk.events.pushEvent = (function () {
return {
commitsQuantity: event.payload.size
, branch: branch
, link: 'https://github.com/' + event.repo.name + '/commits/' + branch
, link: spk.properties.github_web + event.repo.name + '/commits/' + branch
};
};

Expand Down
12 changes: 10 additions & 2 deletions extension/js/bend/events/watch_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ spk.events = spk.events || {};

spk.events.watchEvent = (function () {

var parseGitHubEvent = function (event) {
var parseGitHubEvent = function (event, username) {
var repoOwner = event.repo.name.substring(0, event.repo.name.indexOf('/'));

var link;
if (repoOwner === username) {
link = spk.properties.github_web + event.actor.login
} else {
link = spk.properties.github_web + event.repo.name;
}

return {
user: event.actor.login,
repo: event.repo.name,
link: 'https://github.com/' + event.actor.login
link: link
};
};

Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Spokesman - GitHub's notifications",
"short_name": "Spokesman",
"version": "1.1.1",
"version": "1.1.2",
"description": "Get desktop notifications of events that occur on GitHub that really interest you.",
"browser_action": {
"default_icon": {
Expand Down
2 changes: 2 additions & 0 deletions extension/properties.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"testing": false,
"github_web": "https://github.com/",
"push_branches": [
"master",
"develop",
Expand Down

0 comments on commit f935630

Please sign in to comment.