forked from coala/git-task-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
12 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Controller from '@ember/controller'; | ||
|
||
export default Controller.extend({ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ export default { | |
}, | ||
{ | ||
type: 'gitlab', | ||
identifier: 'coala', | ||
identifier: 'coala/mobans', | ||
}, | ||
], | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import TaskModel from './task'; | ||
|
||
export default TaskModel.extend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Route from '@ember/routing/route'; | ||
import { inject } from '@ember/service'; | ||
|
||
export default Route.extend({ | ||
gitlab: inject(), | ||
store: inject(), | ||
organizations: inject(), | ||
|
||
model(params, transition) { | ||
const { org } = transition.queryParams; | ||
const store = this.get('store'); | ||
const projects = this.get('organizations').fetchGitlabProjects(org); | ||
if (projects.length > 0) { | ||
return this.get('gitlab').tasks({ projects }).then((data) => { | ||
data.forEach((task) => { | ||
store.pushPayload('gitlab-task', task); | ||
}); | ||
return store.peekAll('gitlab-task'); | ||
}); | ||
} | ||
return []; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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; | ||
// Set the default color to 65C8FF, otherwise, we need to refetch the default | ||
// color from `project/:id/labels` endpoint. | ||
task.labels = payload.labels.map(label => ({ color: '65C8FF', name: label })); | ||
task.updatedAt = payload.updated_at; | ||
task.title = payload.title; | ||
task.url = payload.web_url; | ||
|
||
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; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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(...arg) { | ||
this._super(...arg); | ||
this.set('headers', { 'Private-Token': 'sVfZzagWtemrV-suxYK-' }); | ||
}, | ||
|
||
tasks({ projects }) { | ||
const tasks = projects.map((projectId) => { | ||
const embedRepoInfo = taskList => this.fetchRepositoryInfo(projectId) | ||
.then(repoInfo => taskList.map((task) => { | ||
const decoratedTask = Object.assign({}, task); | ||
decoratedTask.repository = repoInfo; | ||
decoratedTask.type = 'gitlab-task'; | ||
return decoratedTask; | ||
})); | ||
return this.fetchIssues(projectId).then(embedRepoInfo); | ||
}); | ||
|
||
return RSVP.all(tasks).then(taskList => | ||
taskList | ||
.reduce((combinedTasks, initialTasklist) => combinedTasks.concat(initialTasklist), [])); | ||
}, | ||
|
||
fetchRepositoryInfo(projectId) { | ||
return this.request(buildProjectUrl(projectId)); | ||
}, | ||
|
||
fetchIssues(projectId) { | ||
return this.request(buildIssuesUrl(projectId)); | ||
}, | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<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}} | ||
{{#unless model}} | ||
<p>This Org doesn't have any gitlab repository.</p> | ||
{{/unless}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Service from '@ember/service'; | ||
import { visit, find } from '@ember/test-helpers'; | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
|
||
// Simulating empty gitlab Projects | ||
const emptyGitlabOrgService = Service.extend({ | ||
fetchGitlabProjects: () => [], | ||
fetch: () => ({}), | ||
}); | ||
|
||
module('Acceptance/tasks/list-gitlab-tasks-test', function listGitlabTaskTests(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
hooks.beforeEach(function beforeEach() { | ||
this.owner.register('service:organizations', emptyGitlabOrgService); | ||
}); | ||
|
||
test('should show no gitlab repository', async function listGitlabTasks(assert) { | ||
await visit('/tasks/gitlab?org=discourse'); | ||
const $noGitlabRepo = find('.is-three-quarters > p'); | ||
assert.equal($noGitlabRepo.innerText, "This Org doesn't have any gitlab repository."); | ||
}); | ||
}); |