Skip to content

Commit 9fcd5df

Browse files
authored
Merge pull request creativecommons#543 from creativecommons/issue_finder_dyn
Load issues dynamically in the Issue Finder
2 parents 26e90a7 + f8d3feb commit 9fcd5df

File tree

5 files changed

+224
-25
lines changed

5 files changed

+224
-25
lines changed

themes/vocabulary_theme/templates/issue_finder.html

-5
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,4 @@ <h1>{{ this.title }}</h1>
3939
</div>
4040
</div>
4141
</div>
42-
<script>
43-
// Transfer all issues to the JavaScript domain
44-
window.issues =
45-
{{ bag('issues.issues')|tojson }}
46-
</script>
4742
{% endblock %}

webpack/js/components.js

+66-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import VueSelect from 'vue-select';
2+
import {Octokit} from '@octokit/rest';
23

34
import {hydrateAppWithData} from "./hydration";
45

@@ -40,7 +41,7 @@ export const IssueCard = {
4041
</h4>
4142
<p class="is-size-6">
4243
<a
43-
:href="issue.url"
44+
:href="issue.html_url"
4445
target="_blank">
4546
<span class="has-color-forest-green">
4647
{{ issue.repo }}#{{ issue.number }}
@@ -70,8 +71,7 @@ export const IssueCard = {
7071
},
7172
computed: {
7273
dateCreated() {
73-
const dateCreated = new Date(this.issue.createdAt * 1000)
74-
const [dateComponent,] = dateCreated.toISOString().split("T")
74+
const [dateComponent,] = this.issue.created_at.split("T")
7575
return dateComponent
7676
}
7777
}
@@ -84,6 +84,20 @@ export const App = {
8484
<div class="columns">
8585
<div class="column is-one-quarter">
8686
<form id="filters" v-if="options.skills.length">
87+
<label for="aim">
88+
<strong>Aim</strong><br/>
89+
I am interested in...
90+
</label>
91+
<VueSelect
92+
v-model="filters.aim"
93+
id="aim"
94+
name="aim"
95+
:options="options.aims"
96+
label="name"
97+
:reduce="aim => aim.code"
98+
:clearable="false"/>
99+
<br/>
100+
<template v-if="filters.aim === 'contribute'">
87101
<label for="skills">
88102
<strong>Skill set*</strong><br/>
89103
Choose up to three skills that you would like to see issues for.
@@ -110,6 +124,7 @@ export const App = {
110124
label="name"
111125
:reduce="experience => experience.code"
112126
:clearable="false"/>
127+
</template>
113128
</form>
114129
<p class="disclaimer">
115130
*Not all issues have skills marked on them, especially if they are
@@ -144,18 +159,24 @@ export const App = {
144159
data() {
145160
return {
146161
options: {
162+
aims: [
163+
{name: 'Contributing code', code: 'contribute'},
164+
{name: 'Triaging issues', code: 'triage'}
165+
],
147166
skills: [],
148167
experiences: [
149168
{name: 'Yes, it is', code: 'beginner'},
150169
{name: 'No, it isn\'t', code: 'experienced'}
151170
]
152171
},
153172
filters: {
173+
aim: 'contribute',
154174
skills: [],
155175
experience: 'experienced'
156176
},
157177
categories: {},
158-
issues: []
178+
issues: [],
179+
octokit: null
159180
}
160181
},
161182
computed: {
@@ -165,26 +186,61 @@ export const App = {
165186
* @returns {array} the array of filtered issues
166187
*/
167188
filteredIssues() {
168-
return window.issues.filter(issue => {
189+
return this.issues.filter(issue => {
190+
// If aim is to triage issues
191+
if (this.filters.aim === 'triage') {
192+
// Show all issues as they all have the label "🚦 status: awaiting triage"
193+
return true
194+
}
195+
169196
// Check experience match
170197
if (this.filters.experience === 'beginner' && !issue.labels.includes('good first issue')) {
171198
return false
172199
}
173200

174201
// Check skill set match
175202
const joinedLabels = issue.labels.join(',')
176-
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
177-
return false
178-
}
179-
180-
return true
203+
return !(this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill)));
181204
}).sort((a, b) => b.createdAt - a.createdAt)
182205
}
183206
},
207+
watch: {
208+
'filters.aim' (to, from) {
209+
if (to !== from) {
210+
this.loadIssues()
211+
}
212+
}
213+
},
214+
methods: {
215+
loadIssues () {
216+
const q = ['org:creativecommons', 'is:open', 'is:issue']
217+
if (this.filters.aim === 'contribute') {
218+
q.push('label:"help wanted"')
219+
} else if (this.filters.aim === 'triage') {
220+
q.push('label:"🚦 status: awaiting triage"')
221+
}
222+
this.octokit.search.issuesAndPullRequests({
223+
q: q.join(' '),
224+
per_page: 100,
225+
sort: 'updated'
226+
}).then(res => {
227+
this.issues = res.data.items
228+
this.issues.forEach(issue => {
229+
issue.labels = issue.labels.map(label => label.name)
230+
231+
const repoUrl = issue.repository_url
232+
issue.repo = repoUrl.slice(repoUrl.lastIndexOf('/') + 1)
233+
})
234+
})
235+
}
236+
},
184237
mounted() {
185238
const BASE_URL = 'https://raw.githubusercontent.com/creativecommons/ccos-scripts/master/normalize_repos'
186239
const FILE_URL = name => `${BASE_URL}/${name}.json`
187240

241+
this.octokit = new Octokit()
242+
this.loadIssues()
243+
188244
Promise
189245
.all([
190246
fetch(FILE_URL('skills'))

webpack/js/hydration.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
export const hydrateAppWithData = (skills, labels) => {
2-
skills = Array.from( // Convert back into an array
3-
new Set( // Remove duplicates
4-
Object.values(skills)
5-
.flat() // Combine all skills
6-
.map(skill => skill.split('/')[0]) // Keep only the prefix
7-
)
2+
skills = Array.from(
3+
new Set( // Remove duplicates
4+
Object.values(skills).flat() // Combine all skills
5+
)
6+
)
7+
const top_level_skills = Array.from(
8+
new Set( // Remove duplicates
9+
skills.map(skill => skill.split('/')[0]) // Keep only the prefix
10+
)
811
)
912

1013
const categories = {}
@@ -35,5 +38,5 @@ export const hydrateAppWithData = (skills, labels) => {
3538
categories[name] = 'skill'
3639
})
3740

38-
return [skills, categories]
41+
return [top_level_skills, categories]
3942
}

webpack/package-lock.json

+147-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"webpack-cli": "^3.3.11"
2727
},
2828
"dependencies": {
29+
"@octokit/rest": "^18.0.6",
2930
"vue": "^2.6.12",
3031
"vue-select": "^3.10.8"
3132
},

0 commit comments

Comments
 (0)