Skip to content

Commit

Permalink
Support GitLab Issues
Browse files Browse the repository at this point in the history
Move GitHub Tasks to github namespace `/tasks/github`
Add a new gitlab route `/tasks/gitlab`
Add a new gitlab serializer

Closes coala#38
  • Loading branch information
bekicot committed Jun 9, 2018
1 parent 59f8038 commit 2284857
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import {inject} from '@ember/service';
export default Controller.extend({
organizations: inject(),
queryParams: ['org'],

});
5 changes: 5 additions & 0 deletions app/controllers/tasks/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Controller from '@ember/controller';

export default Controller.extend({

});
3 changes: 3 additions & 0 deletions app/models/gitlab-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import TaskModel from './task';

export default TaskModel.extend({});
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Router = EmberRouter.extend({
Router.map(function() {
this.route('tasks', function() {
this.route('github');
this.route('gitlab');
});
});

Expand Down
16 changes: 16 additions & 0 deletions app/routes/tasks/gitlab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Route from '@ember/routing/route';
import {inject} from '@ember/service';

export default Route.extend({
gitlab: inject(),
store: inject(),
model() {
const store = this.get('store');
return this.get('gitlab').tasks({projects: ['coala/mobans']}).then(data => {
for (let task of data) {
store.pushPayload('gitlab-task', task);
}
return store.peekAll('gitlab-task');
});
}
});
27 changes: 27 additions & 0 deletions app/serializers/gitlab-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import DS from 'ember-data';

export default DS.JSONSerializer.extend({
pushPayload(store, payload) {
const task = {};
task.id = payload.id
task.bodyText = payload.description
task.commentCount = payload.user_notes_count
task.updatedAt = payload.updated_at
task.url = payload.web_url
task.title = payload.title

task.author = {}
task.author.url = payload.author.web_url
task.author.login = payload.author.username
task.author.avatarUrl = payload.author.avatar_url

task.repository = {}
task.repository.nameWithOwner = payload.repository.path_with_namespace
task.repository.url = payload.repository.web_url

task.isPullRequest = payload._type == 'PullRequest';

store.push(this.normalize(store.modelFor('gitlab-task'), task));
return task;
},
});
58 changes: 58 additions & 0 deletions app/services/gitlab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// https://gitlab.com/api/v4/projects/coala%2Fmobans/issues?order_by=created_at&state=opened
import AjaxService from 'ember-ajax/services/ajax';
import RSVP from 'rsvp';

const ENDPOINT = 'https://gitlab.com/api/v4';
const PROJECT_ENDPOINT = ENDPOINT + '/projects/{projectId}'
const ISSUE_ENDPOINT = PROJECT_ENDPOINT + '/issues?order_by=created_at&state=opened&per_page=100';

function buildIssuesUrl(projectId) {
return ISSUE_ENDPOINT.replace('{projectId}', encodeURIComponent(projectId));
}

function buildProjectUrl(projectId) {
return PROJECT_ENDPOINT.replace('{projectId}', encodeURIComponent(projectId));
}

export default AjaxService.extend({
host: 'https://gitlab.com/',
_issueUrl: '',
init() {
this._super(...arguments);
this.set('headers', {'Private-Token': 'sVfZzagWtemrV-suxYK-'});
},

tasks({projects}) {
let tasks = projects.map((projectId) => {
const embedRepoInfo = (tasks) => {
return new Promise((resolve, reject) => {
this.fetchRepositoryInfo(projectId).then((repoInfo) => {
tasks.map((task) => {
task.repository = repoInfo;
task.type = 'gitlab-task';
return task;
})
resolve(tasks)
}).catch((error) => reject(error));
});
}

return this.fetchIssues(projectId).then(embedRepoInfo)
});

return RSVP.all(tasks).then((tasks) => {
return tasks.reduce((combinedTasks, tasks) => {
return combinedTasks.concat(tasks);
}, [])
})
},

fetchRepositoryInfo(projectId) {
return this.request(buildProjectUrl(projectId));
},

fetchIssues(projectId) {
return this.request(buildIssuesUrl(projectId));
},

});
2 changes: 1 addition & 1 deletion app/templates/tasks.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Organizations
</p>
<ul class="menu-list">
{{#each-in organizations.list as |slug org| }}
{{#each-in organizations.list as |slug org|}}
<li>
{{#link-to (query-params org=slug)}}
{{org.name}}
Expand Down
4 changes: 4 additions & 0 deletions app/templates/tasks/github.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<nav class="panel">
<p class="panel-tabs is-size-4">
<a class="is-active" disabled>GitHub</a>
<a>|</a>
{{#link-to 'tasks.gitlab'}}
GitLab
{{/link-to}}
</p>
</nav>
{{#each tasks as |task|}}
Expand Down
13 changes: 13 additions & 0 deletions app/templates/tasks/gitlab.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<nav class="panel">
<p class="panel-tabs is-size-4">
{{#link-to 'tasks.github'}}
GitHub
{{/link-to}}
<a>|</a>
<a class="is-active" disabled>GitLab</a>
</p>
</nav>
{{#each model as |task|}}
{{task-item task=task}}
<hr>
{{/each}}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@fortawesome/ember-fontawesome": "^0.1.0-8",
"@fortawesome/free-solid-svg-icons": "^5.1.0-8",
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.1.0",
"ember-cli": "~3.1.4",
"ember-cli-app-version": "^3.2.0",
"ember-cli-babel": "^6.6.0",
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,12 @@ electron-to-chromium@^1.3.47:
version "1.3.48"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.48.tgz#d3b0d8593814044e092ece2108fc3ac9aea4b900"

ember-ajax@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ember-ajax/-/ember-ajax-3.1.0.tgz#3db36e67357ef447639517656aeac4bb13e73a9c"
dependencies:
ember-cli-babel "^6.6.0"

[email protected]:
version "0.3.5"
resolved "https://registry.yarnpkg.com/ember-ast-helpers/-/ember-ast-helpers-0.3.5.tgz#db72afd9bc3de03759720ff7b03d4e3b2c7f2351"
Expand Down

0 comments on commit 2284857

Please sign in to comment.