Permalink
Browse files

Old description should remain when updating gist

If when updating, no new description is specified with option '-s'
  • Loading branch information...
baopham committed May 22, 2012
1 parent 6d14419 commit c9eaf835bea30cb5b094d450977b646c5c2da544
Showing with 14 additions and 1 deletion.
  1. +14 −1 autoload/gist.vim
View
@@ -274,7 +274,20 @@ function! s:GistUpdate(content, gistid, gistnm, desc)
if len(filename) == 0 | let filename = s:GistGetFileName(a:gistid) | endif
if len(filename) == 0 | let filename = s:get_current_filename(1) | endif
endif
- if a:desc != ' ' | let gist["description"] = a:desc | endif
+
+ " Update description
+ " If no new description specified, keep the old description
+ if a:desc != ' '
+ let gist["description"] = a:desc
+ else
+ let res = webapi#http#get('https://api.github.com/gists/'.a:gistid, '', { "Authorization": s:GetAuthHeader() })
+ let status = matchstr(matchstr(res.header, '^Status:'), '^[^:]\+: \zs.*')
+ if status =~ '^2'
+ let old_gist = webapi#json#decode(res.content)
+ let gist["description"] = old_gist.description
+ endif
+ endif
+
let gist.files[filename] = { "content": a:content, "filename": filename }
redraw | echon 'Updating gist... '

0 comments on commit c9eaf83

Please sign in to comment.