1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-07 06:25:23 +02:00

remove secrets from JS, make branch name clickable

This commit is contained in:
Elliott Stoneham 2016-06-02 14:56:50 +01:00
parent 8a6af3d0a1
commit 9cebfbe219
2 changed files with 83 additions and 50 deletions

View file

@ -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) {

View file

@ -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(`
<p>There are {{ .CommitCount }} commits for branch <span class="bold">{{.Config.Branch}}</span> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a></p>
<p>There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a></p>
<div class="github-board">
{{range $data := .Data}}
<div class="github-group-title">
@ -417,6 +441,7 @@ type githubBranch struct {
ID string `json:"id"`
Name string `json:"name"`
Included bool `json:"included"`
URL string `json:"url"`
}
type githubBranchCommits struct {
@ -434,15 +459,17 @@ type githubCommit struct {
}
type githubConfig struct {
AppKey string `json:"appKey"` // TODO keep?
Token string `json:"token"`
Owner string `json:"owner"`
Repo string `json:"repo_name"`
Branch string `json:"branch"`
RepoInfo githubRepo `json:"repo"`
ClientID string `json:"clientId"`
CallbackURL string `json:"callbackUrl"`
Lists []githubRepo `json:"lists"`
AppKey string `json:"appKey"` // TODO keep?
Token string `json:"token"`
Owner string `json:"owner"`
Repo string `json:"repo_name"`
Branch string `json:"branch"`
BranchURL string `json:"branchURL"`
BranchSince string `json:"branchSince"`
RepoInfo githubRepo `json:"repo"`
ClientID string `json:"clientId"`
CallbackURL string `json:"callbackUrl"`
Lists []githubBranch `json:"lists"`
}
func (c *githubConfig) Clean() {
@ -453,6 +480,7 @@ func (c *githubConfig) Clean() {
for _, l := range c.Lists {
if l.Included {
c.Branch = l.Name
c.BranchURL = l.URL
break
}
}