Skip to content

Commit d4516dd

Browse files
committed
graphql: Use graphql for GitHub
Use graphql for GitHub API Add support to coala Add GitHub token modal
1 parent e706d74 commit d4516dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3139
-1809
lines changed

app/adapters/application.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/adapters/issue.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/adapters/repository.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/components/settings-modal.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Component from '@ember/component';
2+
import {oneWay} from '@ember/object/computed';
3+
import {inject} from '@ember/service';
4+
5+
6+
export default Component.extend({
7+
// Services
8+
userSettings: inject(),
9+
10+
// Properties
11+
token_github_com: oneWay('userSettings.tokens.github_com'),
12+
13+
init() {
14+
this._super(...arguments);
15+
},
16+
actions: {
17+
hideModal() {
18+
this.set('isActive', false);
19+
this.userSettings.setSetting('githubTokenModalSeen', true);
20+
},
21+
saveSettings() {
22+
this.userSettings.setToken('github_com', this.get('token_github_com'));
23+
},
24+
},
25+
classNames: ['modal'],
26+
classNameBindings: ['isActive'],
27+
isActive: false
28+
});

app/components/task-item.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Component from '@ember/component';
2+
3+
export default Component.extend({
4+
init() {
5+
this._super(...arguments);
6+
},
7+
didInsertElement() {
8+
this.$().linkify({
9+
validate: {
10+
url: function (value) {
11+
return /^(http|ftp)s?:\/\//.test(value);
12+
}
13+
},
14+
formatHref: function (href, type) {
15+
if (type === 'mention') {
16+
href = 'https://github.com/' +
17+
href.substring(1);
18+
}
19+
return href;
20+
}
21+
});
22+
}
23+
});

app/controllers/application.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import Controller from '@ember/controller';
22

33
export default Controller.extend({
44
toggleSidenav: true,
5+
56
actions: {
6-
searchIssues(query) {
7-
this.transitionToRoute('issues', { queryParams: { q: query } });
8-
},
9-
toggleSidenav() {
10-
return this.set('toggleSidenav', !this.get('toggleSidenav'));
11-
},
12-
searchByOrg(org) {
13-
this.send('searchIssues', org.query.q);
7+
showSettingsModal() {
8+
this.set('showModal', true);
149
}
1510
}
1611
});

app/controllers/issues.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/controllers/tasks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Controller from '@ember/controller';
2+
import {inject} from '@ember/service';
3+
4+
export default Controller.extend({
5+
organizations: inject(),
6+
queryParams: ['org']
7+
});

app/data/organizations.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
coala: {
3+
name: 'coala association e.V.',
4+
trackers: [
5+
{
6+
type: 'github',
7+
identifier: 'coala'
8+
},
9+
{
10+
type: 'gitlab',
11+
identifier: 'coala'
12+
}
13+
]
14+
},
15+
"52-north-initiative-for-geospatial-open-source-software-gmbh": {
16+
name: '52° North Initiative for Geospatial Open Source Software GmbH',
17+
trackers: [
18+
{
19+
type: 'github',
20+
identifier: '52North'
21+
}
22+
]
23+
}
24+
}

app/graphql/github.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import Handlebars from 'handlebars';
2+
import {isIterable} from '../utils/commons';
3+
4+
const TEMPLATES = {
5+
tasks:
6+
`
7+
{
8+
rateLimit {
9+
remaining
10+
}
11+
search(query: "{{query}}", type: ISSUE, first: 100 ) {
12+
nodes {
13+
type: __typename
14+
... on Issue {
15+
title
16+
author {
17+
url
18+
login
19+
avatarUrl
20+
}
21+
bodyText
22+
url
23+
updatedAt
24+
repository {
25+
nameWithOwner
26+
owner {
27+
avatarUrl
28+
}
29+
url
30+
}
31+
comments {
32+
totalCount
33+
}
34+
}
35+
... on PullRequest {
36+
title
37+
author {
38+
url
39+
login
40+
avatarUrl
41+
}
42+
bodyText
43+
url
44+
updatedAt
45+
repository {
46+
nameWithOwner
47+
owner {
48+
avatarUrl
49+
}
50+
url
51+
}
52+
comments {
53+
totalCount
54+
}
55+
}
56+
}
57+
}
58+
}
59+
`
60+
}
61+
function queryBuilder({orgs}) {
62+
let queries = ["sort:updated-desc", "state:open"];
63+
if(isIterable(orgs)) {
64+
queries = orgs.reduce((a,b) => [...a, "user:" + b], queries)
65+
}
66+
return queries.join(" ")
67+
}
68+
export const generate = (templateType, context) => {
69+
if(!TEMPLATES[templateType])
70+
throw new Error("Invalid GitHub GraphQL `templateType`");
71+
72+
const query = queryBuilder({orgs: context && context['orgs']});
73+
74+
let template = Handlebars.compile(TEMPLATES[templateType]);
75+
return template({query: query});
76+
}

0 commit comments

Comments
 (0)