Skip to content
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

Feature/git-notes (WIP) #6

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
},
"engines": {
"node": ">= 8.9.0",
"npm": ">= 5.6.0",
"yarn": ">= 1.6.0"
"npm": ">= 5.6.0"
},
"browserslist": [
"> 1%",
Expand Down
39 changes: 39 additions & 0 deletions src/components/git-notes/CreateButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template lang="pug">
q-btn(icon="create" v-bind="$attrs" @click="add")
</template>

<style>
</style>

<script>
import { run } from '@/node-utils'

/** A button to insert notes
* @prop {String} notes notes that want to be inserted
* @prop {String} commitId SHA-1 of commits. If not provided, it will add notes in the HEAD (current commit)
* @prop {String} workingDirectory in case the application not runned in project directory
* @fires success when notes is committed
* @fires fail#ErrorMessage when notes fail to commit
* @example gn-button(:notes="markdownNotes" commitId="98e34" workingDirectory="/home/user/projects")
*/
export default {
name: 'GitNotesCreateButton',
props: {
notes: {
type: String,
required: true
},
commitId: String,
workingDirectory: String
},
methods: {
add () {
const cwd = this.workingDirectory
const sha = this.commitId
run('git', ['notes', '--ref=utopian', 'add', '-m', this.notes, ...(sha ? [sha] : [])], { cwd })
.then(data => this.$emit('success'))
.catch(data => this.$emit('fail', data.toString()))
}
}
}
</script>
34 changes: 34 additions & 0 deletions src/components/git-notes/RemoveButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template lang="pug">
q-btn(icon="delete" v-bind="$attrs" @click="remove")
</template>

<style>
</style>

<script>
import { run } from '@/node-utils'

/** A button to remove notes
* @prop {String} commitId SHA-1 of commits. If not provided, it will remove notes in the HEAD (current commit)
* @prop {String} workingDirectory in case the application not runned in project directory
* @fires success when notes is removed
* @fires fail#ErrorMessage when notes fail to removed
* @example gn-button(commitId="98e34" workingDirectory="/home/user/projects")
*/
export default {
name: 'GitNotesRemoveButton',
props: {
commitId: String,
workingDirectory: String
},
methods: {
remove () {
const cwd = this.workingDirectory
const sha = this.commitId
run('git', ['notes', '--ref=utopian', 'remove', ...(sha ? [sha] : [])], { cwd })
.then(data => this.$emit('success'))
.catch(data => this.$emit('fail', data.toString()))
}
}
}
</script>
35 changes: 35 additions & 0 deletions src/components/git-notes/ShowButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template lang="pug">
q-btn(icon="visibility" v-bind="$attrs" @click="show")
</template>

<style>
</style>

<script>
import { run, runSync } from '@/node-utils'

/** A button to insert notes
* @prop {String} commitId SHA-1 of commits. If not provided, it will show notes in the HEAD (current commit)
* @prop {String} workingDirectory in case the application not runned in project directory
* @fires success#Notes when notes can be retrieved
* @fires fail#ErrorMessage when notes fail to be retrieved
* @example gn-button(commitId="98e34" workingDirectory="/home/user/projects")
*/
export default {
name: 'GitNotesCreateButton',
props: {
commitId: String,
workingDirectory: String
},
methods: {
show () {
const cwd = this.workingDirectory
const sha = this.commitId
const getHead = [runSync('git', ['rev-parse', 'HEAD'])]
run('git', ['notes', '--ref=utopian', 'show', ...(sha ? [sha] : getHead)], { cwd })
.then(data => this.$emit('success'), data.stdout)
.catch(data => this.$emit('fail', data.toString()))
}
}
}
</script>
18 changes: 18 additions & 0 deletions src/node-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { promisify } from 'util'
import { execFile, execFileSync } from 'child_process'

const elecOpts = {
shell: true,
windowsHide: true,
encoding: 'utf-8'
}

export const run = (cmd, args, opts) => promisify(execFile)(cmd, args, {
...elecOpts,
...opts
})

export const runSync = (cmd, args, opts) => promisify(execFileSync)(cmd, args, {
...elecOpts,
...opts
})
25 changes: 25 additions & 0 deletions src/pages/__Test__.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template lang="pug">
q-page.flex.flex-center
.column.flex-center
p {{ $t('pages.dashboard.title') }}
gn-button(label="Create Notes")
</template>

<style>
</style>

<script>
import GnButton from '@/components/git-notes/CreateButton.vue'

export default {
name: 'PageDashboard',
components: {
GnButton
},
meta () {
return {
title: 'Dashboard'
}
}
}
</script>
2 changes: 1 addition & 1 deletion test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ localVue.use(VueRouter)
localVue.use(Quasar)

export const mountQuasar = (component, options = {}) => {
const app= {}
const app = {}
const store = new Vuex.Store({})
const router = new VueRouter()

Expand Down