-
Notifications
You must be signed in to change notification settings - Fork 14
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
[WIP]Support GitLab #44
Open
bekicot
wants to merge
1
commit into
coala:master
Choose a base branch
from
bekicot:support_gitlab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,53 @@ | ||
import { inject } from '@ember/service'; | ||
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({ | ||
userSettings: inject(), | ||
|
||
host: 'https://gitlab.com/', | ||
_issueUrl: '', | ||
|
||
init(...arg) { | ||
this._super(...arg); | ||
this.set('headers', { 'Private-Token': this.get('userSettings').tokens.get('gitlab_com') }); | ||
}, | ||
|
||
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
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."); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is obviously wrong, as it is not an org identifier. It is a project identifier.
This is not too different from the problem I raised in the PR a month ago.
#44 (comment)
fetchGitlabProjects
still doesnt get the projects for the org.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.
Identifier in gitlab currently only support per repository, however, in github, only support per organization.
In gitlab, supporting per org, will make multiple request.
It fit nicely with wikidata where, it already support github organization, but not gitlab. It can be identified via issue tracker used, which is currently support full link.