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 Jul 9, 2018
1 parent b09fdec commit 3704f11
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 0 deletions.
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 mainRoute() {
return this.route('tasks', function tasksRoute() {
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));
},

});
9 changes: 9 additions & 0 deletions app/templates/tasks/github.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<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|}}
{{task-item task=task}}
<hr>
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}}

0 comments on commit 3704f11

Please sign in to comment.