From 06f7db7ce0c1160cb3234cd30f5c053abd25bb45 Mon Sep 17 00:00:00 2001
From: dodosophia <376697534@qq.com>
Date: Mon, 29 Jun 2020 15:51:51 +0800
Subject: [PATCH 1/3] =?UTF-8?q?add=20Feature=EF=BC=9A=20=20=20Show=20snaps?=
=?UTF-8?q?hot,=20storage=20channel=20info=20=20=20Support=20export=20snap?=
=?UTF-8?q?shot=20to=20add=20to=20bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend/src/api.js | 5 +-
.../src/components/event/EventInspector.vue | 3 +
.../src/components/form/AttachmentItem.vue | 6 +-
.../{FileModal.vue => AttachmentModal.vue} | 24 +++++--
.../src/components/form/AttachmentsList.vue | 18 +++++-
frontend/src/components/form/BugItForm.vue | 6 +-
frontend/src/components/form/SnapshotItem.vue | 24 +++++++
frontend/src/store/event.js | 4 +-
frontend/src/store/form.js | 63 ++++++++++---------
lyrebird_bugit/apis.py | 6 +-
lyrebird_bugit/attachment.py | 23 +++++++
setup.py | 2 +-
12 files changed, 138 insertions(+), 46 deletions(-)
rename frontend/src/components/form/{FileModal.vue => AttachmentModal.vue} (73%)
create mode 100644 frontend/src/components/form/SnapshotItem.vue
create mode 100644 lyrebird_bugit/attachment.py
diff --git a/frontend/src/api.js b/frontend/src/api.js
index 06286a5..958a26f 100644
--- a/frontend/src/api.js
+++ b/frontend/src/api.js
@@ -54,14 +54,15 @@ export const saveImage = (id, imageData) => {
})
}
-export const createIssue = (templateInfo, issue, attachments) => {
+export const createIssue = (templateInfo, issue, attachments, snapshots) => {
return axios({
url: API_PREFIX + '/issue',
method: 'POST',
data: {
template: templateInfo,
issue,
- attachments
+ attachments,
+ snapshots
}
})
}
diff --git a/frontend/src/components/event/EventInspector.vue b/frontend/src/components/event/EventInspector.vue
index 9c7a524..997ba76 100644
--- a/frontend/src/components/event/EventInspector.vue
+++ b/frontend/src/components/event/EventInspector.vue
@@ -172,6 +172,9 @@ export default {
message: eventObj.message
})
}
+ if (eventObj.snapshot) {
+ this.$bus.$emit('addSnapshot', eventObj)
+ }
if (eventObj.attachments) {
this.$bus.$emit('addAttachments', eventObj.attachments)
}
diff --git a/frontend/src/components/form/AttachmentItem.vue b/frontend/src/components/form/AttachmentItem.vue
index ebcb94d..7b15349 100644
--- a/frontend/src/components/form/AttachmentItem.vue
+++ b/frontend/src/components/form/AttachmentItem.vue
@@ -1,7 +1,7 @@
- {{data.name}}
+ {{data.name}}
delete
@@ -16,8 +16,8 @@ export default {
deleteAttach(data) {
this.$store.dispatch('removeAttachment', { id: data.id, index: this.index })
},
- displayFile(data) {
- this.$bus.$emit('displayFile', data)
+ displayAttach(data) {
+ this.$bus.$emit('displayAttach', data)
}
}
}
diff --git a/frontend/src/components/form/FileModal.vue b/frontend/src/components/form/AttachmentModal.vue
similarity index 73%
rename from frontend/src/components/form/FileModal.vue
rename to frontend/src/components/form/AttachmentModal.vue
index bc03d6f..bf0ca49 100644
--- a/frontend/src/components/form/FileModal.vue
+++ b/frontend/src/components/form/AttachmentModal.vue
@@ -13,6 +13,9 @@
:src="'/plugins/bugit/api/attachments/' + this.attachmentId"
/>
+
+
+
@@ -31,20 +34,24 @@
diff --git a/frontend/src/store/event.js b/frontend/src/store/event.js
index 76c0e44..60fadce 100644
--- a/frontend/src/store/event.js
+++ b/frontend/src/store/event.js
@@ -4,7 +4,7 @@ import { bus } from '@/eventbus'
export default {
state: {
channelNames: [],
- channelFilters: ['flow', 'notice', 'page', 'android.crash', 'ios.crash'],
+ channelFilters: ['flow', 'notice', 'page', 'android.crash', 'ios.crash', 'snapshot', 'storage'],
events: [],
selectedEventId: null,
eventDetail: '',
@@ -33,7 +33,7 @@ export default {
actions: {
loadChannelNames({ commit }) {
// Filter out the target channel
- commit('setChannelNames', ['flow', 'notice', 'page', 'android.crash', 'ios.crash'])
+ commit('setChannelNames', ['flow', 'notice', 'page', 'android.crash', 'ios.crash', 'snapshot', 'storage'])
},
loadEvents({ state, commit }, options = {}) {
let eventId = null
diff --git a/frontend/src/store/form.js b/frontend/src/store/form.js
index b60ac2d..90215f1 100644
--- a/frontend/src/store/form.js
+++ b/frontend/src/store/form.js
@@ -11,6 +11,7 @@ export default {
ruleValidate: null,
formValue: {},
attachmentsList: [],
+ snapshotList: [],
loadAttachmentCount: 0,
shownFileName: null,
submitLock: false,
@@ -21,22 +22,22 @@ export default {
}
},
mutations: {
- setFormData(state, sourceData) {
+ setFormData (state, sourceData) {
state.templateDetail[sourceData.index].value = sourceData.value
},
- setTemplates(state, templates) {
+ setTemplates (state, templates) {
state.templates = templates
},
- setSelectedTemplateIndex(state, selectedTemplateIndex) {
+ setSelectedTemplateIndex (state, selectedTemplateIndex) {
state.selectedTemplateIndex = selectedTemplateIndex
},
- setTemplateDetail(state, templateDetail) {
+ setTemplateDetail (state, templateDetail) {
state.templateDetail = templateDetail
},
- setSubmitLock(state, isLock) {
+ setSubmitLock (state, isLock) {
state.submitLock = isLock
},
- updateFormInfo(state, template) {
+ updateFormInfo (state, template) {
for (let i in state.metadata) {
if (state.metadata[i].key === template) {
state.formInfo = state.metadata[i]
@@ -44,43 +45,50 @@ export default {
}
}
},
- updateRuleValidate(state, ruleValidate) {
+ updateRuleValidate (state, ruleValidate) {
state.ruleValidate = ruleValidate
},
- updateFormValue(state, formValue) {
+ updateFormValue (state, formValue) {
state.formValue = formValue
},
- deleteFormValue(state, formValue) {
+ deleteFormValue (state, formValue) {
state.formValue = {}
},
- updateExtraMsg(state, msg) {
+ updateExtraMsg (state, msg) {
state.templateDetail[msg.index].extraMsg = msg.value
},
- addExtraMsg(state, msg) {
+ addExtraMsg (state, msg) {
let value = msg.value
state.templateDetail[msg.index].extraMsg.push(value)
},
- deleteExtraMsg(state, indexes) {
+ deleteExtraMsg (state, indexes) {
state.templateDetail[indexes.propsIndex].extraMsg.splice(indexes.index, 1)
},
- updateAttachmentsList(state, attachmentsList) {
+ updateAttachmentsList (state, attachmentsList) {
state.attachmentsList = attachmentsList
},
- addAttachmentsList(state, attachment) {
+ addAttachmentsList (state, attachment) {
state.attachmentsList.push(attachment)
},
- updateShownFileName(state, name) {
+ updateShownFileName (state, name) {
state.shownFileName = name
},
- updateShownFileContent(state, fileInfo) {
+ updateShownFileContent (state, fileInfo) {
state.shownFileContent = fileInfo
},
- deleteAttachment(state, index) {
+ deleteAttachment (state, index) {
state.attachmentsList.splice(index, 1)
+ },
+ addSnapshot (state, snapshot) {
+ let fileName = 'snapshot_' + snapshot.id
+ state.snapshotList.push({ 'name': fileName, 'eventObj': snapshot })
+ },
+ deleteSnapshot (state, index) {
+ state.snapshotList.splice(index, 1)
}
},
actions: {
- loadTemplateList({ commit, dispatch }) {
+ loadTemplateList ({ commit, dispatch }) {
api.getTemplate().then(response => {
if (response.data.code === 1000) {
commit('setSelectedTemplateIndex', response.data.selected_index)
@@ -91,7 +99,7 @@ export default {
}
})
},
- loadTemplate({ state, commit }) {
+ loadTemplate ({ state, commit }) {
if (state.selectedTemplateIndex === null) {
return
}
@@ -100,11 +108,11 @@ export default {
commit('setTemplateDetail', response.data)
})
},
- updateSelectedTemplateIndex({ commit, dispatch }, selectedTemplateIndex) {
+ updateSelectedTemplateIndex ({ commit, dispatch }, selectedTemplateIndex) {
commit('setSelectedTemplateIndex', selectedTemplateIndex)
dispatch('loadTemplate')
},
- setExtraMsgUpward({ state, commit }, indexes) {
+ setExtraMsgUpward ({ state, commit }, indexes) {
let descFormEventbus = state.templateDetail[indexes.propsIndex].extraMsg
let index = indexes.index
let upDesc = descFormEventbus[index]
@@ -118,14 +126,14 @@ export default {
}
commit('updateExtraMsg', { index: indexes.propsIndex, value: newDescFormEventbus })
},
- saveEditedImage({ state, commit }, { id, imageData }) {
+ saveEditedImage ({ state, commit }, { id, imageData }) {
api.saveImage(id, imageData)
},
- submit({ state, commit }) {
+ submit ({ state, commit }) {
bus.$emit('message', 'Submitting issue ...')
commit('setSubmitLock', true)
api.createIssue(state.templates[state.selectedTemplateIndex], state.templateDetail,
- state.attachmentsList)
+ state.attachmentsList, state.snapshotList)
.then(response => {
bus.$emit('message', response.data)
commit('setSubmitLock', false)
@@ -133,9 +141,8 @@ export default {
bus.$emit('message', response.data)
commit('setSubmitLock', false)
})
-
},
- loadAttachment({ state, commit }) {
+ loadAttachment ({ state, commit }) {
api.getAttachments().then(response => {
commit('updateAttachmentsList', response.data)
if (state.attachmentsList.length > 0 && state.loadAttachmentCount > 0) {
@@ -145,11 +152,11 @@ export default {
state.loadAttachmentCount += 1
})
},
- removeAttachment({ commit }, attachment) {
+ removeAttachment ({ commit }, attachment) {
commit('deleteAttachment', attachment.index)
api.removeAttachment(attachment.id)
},
- saveCache({ state }) {
+ saveCache ({ state }) {
if (state.selectedTemplateIndex === null) {
return
}
diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py
index f780b9f..80105c4 100644
--- a/lyrebird_bugit/apis.py
+++ b/lyrebird_bugit/apis.py
@@ -12,13 +12,13 @@
from . import event_handler
from . import template_loader
from . import cache
+from . import attachment
import traceback
from hashlib import md5
logger = log.get_logger()
-
def template():
if request.method == 'GET':
templates = template_loader.template_list()
@@ -57,7 +57,11 @@ def issue():
issue_data = issue_req['issue']
attachments = issue_req['attachments']
+ snapshots = issue_req['snapshots']
+ # Export Snapshot
+ for snapshot in snapshots:
+ attachments.append(attachment.export_snapshot(snapshot))
# Set bugit script context
context = {'issue': issue_data, 'attachments': attachments}
# Set submit actions
diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py
new file mode 100644
index 0000000..5514ff0
--- /dev/null
+++ b/lyrebird_bugit/attachment.py
@@ -0,0 +1,23 @@
+from pathlib import Path
+import codecs
+import json
+import lyrebird
+import requests
+from lyrebird.application import config
+
+BUGIT_STORAGE = lyrebird.get_plugin_storage()
+ATTACHMENT_ROOT = Path(BUGIT_STORAGE)/'attachments'
+
+EXPORT_URL = 'http://%s:%s/api/snapshot/export/event' %(config.get('ip'), config.get('mock.port'))
+
+def _check_dir():
+ if not ATTACHMENT_ROOT.exists():
+ CACHE_ROOT.mkdir(parents=True, exist_ok=True)
+
+def export_snapshot(snapshot):
+ _check_dir()
+ file_content = requests.post(EXPORT_URL,json=snapshot['eventObj'],stream=True).content
+ with codecs.open(str(ATTACHMENT_ROOT / snapshot['name'])+'.lb', 'wb') as f:
+ f.write(file_content)
+ return {'id':snapshot['eventObj']['id'],'name':snapshot['name']+'.lb',
+ 'path':str(ATTACHMENT_ROOT / snapshot['name'])+'.lb'}
diff --git a/setup.py b/setup.py
index 5a1267d..4f35a68 100644
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@
setup(
name='lyrebird-bugit',
- version='1.2.3',
+ version='1.3.0',
packages=['lyrebird_bugit'],
url='https://github.com/Meituan-Dianping/lyrebird-bugit',
author='HBQA',
From b0e304e14ead606439fc32ea5d389e1cc2d1a9af Mon Sep 17 00:00:00 2001
From: dodosophia <376697534@qq.com>
Date: Tue, 30 Jun 2020 10:15:48 +0800
Subject: [PATCH 2/3] get default channel from api delete attachments after
submit issue
---
frontend/src/api.js | 4 ++--
frontend/src/components/event/ChannelColumn.vue | 2 ++
frontend/src/store/event.js | 15 ++++++++++++---
frontend/src/store/form.js | 2 +-
lyrebird_bugit/apis.py | 2 ++
lyrebird_bugit/attachment.py | 12 +++++++++---
6 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/frontend/src/api.js b/frontend/src/api.js
index 958a26f..c485fcc 100644
--- a/frontend/src/api.js
+++ b/frontend/src/api.js
@@ -40,9 +40,9 @@ export const getEvent = (options) => {
})
}
-export const getChannelNames = () => {
+export const getDefaultChannelNames = () => {
return axios({
- url: '/api/channel'
+ url: '/api/channel/default'
})
}
diff --git a/frontend/src/components/event/ChannelColumn.vue b/frontend/src/components/event/ChannelColumn.vue
index f8467f2..8251667 100644
--- a/frontend/src/components/event/ChannelColumn.vue
+++ b/frontend/src/components/event/ChannelColumn.vue
@@ -24,6 +24,8 @@ export default {
return '#0fccbf'
} else if (this.channel === 'notice') {
return '#ff9900'
+ } else if (this.channel === 'snapshot') {
+ return '#52A7F9'
} else {
return '#808695'
}
diff --git a/frontend/src/store/event.js b/frontend/src/store/event.js
index 60fadce..7fbde8f 100644
--- a/frontend/src/store/event.js
+++ b/frontend/src/store/event.js
@@ -4,7 +4,7 @@ import { bus } from '@/eventbus'
export default {
state: {
channelNames: [],
- channelFilters: ['flow', 'notice', 'page', 'android.crash', 'ios.crash', 'snapshot', 'storage'],
+ channelFilters: ['flow'],
events: [],
selectedEventId: null,
eventDetail: '',
@@ -33,7 +33,12 @@ export default {
actions: {
loadChannelNames({ commit }) {
// Filter out the target channel
- commit('setChannelNames', ['flow', 'notice', 'page', 'android.crash', 'ios.crash', 'snapshot', 'storage'])
+ api.getDefaultChannelNames().then(response => {
+ if (response.data.code === 1000) {
+ commit('setChannelNames', response.data.data)
+ commit('setChannelFilters', response.data.data)
+ }
+ })
},
loadEvents({ state, commit }, options = {}) {
let eventId = null
@@ -74,7 +79,11 @@ export default {
dispatch('updateChannelFilters', ['notice'])
},
showAll({ dispatch }) {
- dispatch('updateChannelFilters', ['flow', 'notice', 'page', 'android.crash', 'ios.crash'])
+ api.getDefaultChannelNames().then(response => {
+ if (response.data.code === 1000) {
+ dispatch('updateChannelFilters', response.data.data)
+ }
+ })
}
}
}
diff --git a/frontend/src/store/form.js b/frontend/src/store/form.js
index 90215f1..58f32b1 100644
--- a/frontend/src/store/form.js
+++ b/frontend/src/store/form.js
@@ -147,7 +147,7 @@ export default {
commit('updateAttachmentsList', response.data)
if (state.attachmentsList.length > 0 && state.loadAttachmentCount > 0) {
const index = state.attachmentsList.length - 1
- bus.$emit('displayFile', state.attachmentsList[index])
+ bus.$emit('displayAttach', state.attachmentsList[index])
}
state.loadAttachmentCount += 1
})
diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py
index 80105c4..417b2bd 100644
--- a/lyrebird_bugit/apis.py
+++ b/lyrebird_bugit/apis.py
@@ -89,6 +89,8 @@ def issue():
'data': issue_data
}
})
+ #Delete Snapshot
+ attachment.remove_attach()
return application.make_ok_response(message="Create issue success!")
diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py
index 5514ff0..aae6cf2 100644
--- a/lyrebird_bugit/attachment.py
+++ b/lyrebird_bugit/attachment.py
@@ -1,18 +1,18 @@
from pathlib import Path
import codecs
-import json
import lyrebird
import requests
+import shutil
from lyrebird.application import config
BUGIT_STORAGE = lyrebird.get_plugin_storage()
ATTACHMENT_ROOT = Path(BUGIT_STORAGE)/'attachments'
-EXPORT_URL = 'http://%s:%s/api/snapshot/export/event' %(config.get('ip'), config.get('mock.port'))
+EXPORT_URL = f'http://{config.get("ip")}:{config.get("mock.port")}/api/snapshot/export/event'
def _check_dir():
if not ATTACHMENT_ROOT.exists():
- CACHE_ROOT.mkdir(parents=True, exist_ok=True)
+ ATTACHMENT_ROOT.mkdir(parents=True, exist_ok=True)
def export_snapshot(snapshot):
_check_dir()
@@ -21,3 +21,9 @@ def export_snapshot(snapshot):
f.write(file_content)
return {'id':snapshot['eventObj']['id'],'name':snapshot['name']+'.lb',
'path':str(ATTACHMENT_ROOT / snapshot['name'])+'.lb'}
+
+def remove_attach():
+ if not ATTACHMENT_ROOT.exists():
+ pass
+ else:
+ shutil.rmtree(ATTACHMENT_ROOT)
From 1aeafa2c5f8f67940b75a0127a34febcdf64db79 Mon Sep 17 00:00:00 2001
From: dodosophia <376697534@qq.com>
Date: Tue, 30 Jun 2020 11:07:42 +0800
Subject: [PATCH 3/3] fix if of url
---
lyrebird_bugit/attachment.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py
index aae6cf2..1e32c5f 100644
--- a/lyrebird_bugit/attachment.py
+++ b/lyrebird_bugit/attachment.py
@@ -8,7 +8,7 @@
BUGIT_STORAGE = lyrebird.get_plugin_storage()
ATTACHMENT_ROOT = Path(BUGIT_STORAGE)/'attachments'
-EXPORT_URL = f'http://{config.get("ip")}:{config.get("mock.port")}/api/snapshot/export/event'
+EXPORT_URL = f'http://127.0.0.1:{config.get("mock.port")}/api/snapshot/export/event'
def _check_dir():
if not ATTACHMENT_ROOT.exists():