diff --git a/app/app/components/section/github/type-editor.js b/app/app/components/section/github/type-editor.js index 17330ef9..1badf76b 100644 --- a/app/app/components/section/github/type-editor.js +++ b/app/app/components/section/github/type-editor.js @@ -24,44 +24,52 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, noRepos: false, didReceiveAttrs() { - let config = {}; - try { - config = JSON.parse(this.get('meta.config')); - } catch (e) {} + let self = this; + let page = this.get('page'); + console.log(this.get('config.clientId')); - if (is.empty(config)) { - config = { - clientId: "8574d0c34142dcdc53f6", - callbackUrl: "https://localhost:5001/api/public/validate?section=github", - token: "", - repo: null, - lists: [], - owner: "", - repo_name: "", - branch: "" - }; + if (is.undefined(this.get('config.clientId')) || is.undefined(this.get('config.callbackUrl'))) { + self.get('sectionService').fetch(page, "config", {}) + .then(function(cfg) { + let config = {}; + + try { + config = JSON.parse(self.get('meta.config')); + } catch (e) {} + + config = { + clientId: cfg.clientID, + callbackUrl: cfg.authorizationCallbackURL, + token: "", + repo: null, + lists: [], + owner: "", + repo_name: "", + branch: "", + branchURL: "", + branchSince: "" + }; + self.set('config', config); + + // On auth callback capture code + let code = window.location.search; + + if (is.not.undefined(code) && is.not.null(code)) { + let tok = code.replace("?code=", ""); + if (is.not.empty(code)) { + self.set('config.token', tok); + self.send('authStage2'); + } + } else { + if (self.get('config.token') === "") { + self.send('auth'); + } + } + }, function(error) { //jshint ignore: line + console.log(error); + }); } - - this.set('config', config); - - - // On auth callback capture code - let code = window.location.search; - if (is.not.undefined(code) && is.not.null(code)) { - let tok = code.replace("?code=", ""); - if (is.not.empty(code)) { - this.set('config.token', tok); - this.send('authStage2'); - } - } - - if ((this.get('config.clientId') === "" || this.get('config.token') === "")) { - - this.send('auth'); - - } - }, willDestroyElement() { @@ -160,8 +168,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, auth() { let self = this; - - self.set('busy', true); self.set('authenticated', false); let target = "https://github.com/login/oauth/authorize?client_id=" + self.get('config.clientId') + @@ -169,7 +175,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin, "&state=" + encodeURIComponent(window.location.href); window.location.href = target; - }, onRepoChange(thisRepo) { diff --git a/documize/section/github/github.go b/documize/section/github/github.go index cff8757d..21ea8ca3 100644 --- a/documize/section/github/github.go +++ b/documize/section/github/github.go @@ -21,6 +21,7 @@ import ( "net/url" "sort" "strings" + "time" "github.com/documize/community/documize/api/request" "github.com/documize/community/wordsmith/log" @@ -85,6 +86,17 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) { return } + if method == "config" { + var ret struct { + CID string `json:"clientID"` + URL string `json:"authorizationCallbackURL"` + } + ret.CID = clientID() + ret.URL = authorizationCallbackURL() + writeJSON(w, ret) + return + } + defer r.Body.Close() body, err := ioutil.ReadAll(r.Body) @@ -205,6 +217,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) { Name: *vb.Name, ID: fmt.Sprintf("%s:%s:%s:%d", config.Owner, config.Repo, *vb.Name, kc), Included: false, + URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name, } } @@ -227,8 +240,19 @@ func (*GithubT) githubClient(config githubConfig) *gogithub.Client { func (*GithubT) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) { - guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, - &gogithub.CommitsListOptions{SHA: config.Branch, ListOptions: gogithub.ListOptions{PerPage: 100}}) + opts := &gogithub.CommitsListOptions{ + SHA: config.Branch, + ListOptions: gogithub.ListOptions{PerPage: 100}} + + var since time.Time + + err := since.UnmarshalText([]byte(config.BranchSince)) + if err == nil { + opts.Since = since + } + + guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, opts) + if err != nil { return nil, err } @@ -347,7 +371,7 @@ func (*GithubT) Render(config, data string) string { var err error t, err = t.Parse(` -
There are {{ .CommitCount }} commits for branch {{.Config.Branch}} of repository {{.Repo.Name}}.
+There are {{ .CommitCount }} commits for branch {{.Config.Branch}} of repository {{.Repo.Name}}.