aboutsummaryrefslogtreecommitdiff
path: root/modules/base
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-26 14:38:14 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-26 14:38:14 +0800
commit9dbc808c7b71fc97015346704bb3d3db4918aba0 (patch)
treef0d76b189a0137bcb455e548e52805787d680fa7 /modules/base
parentf9024b3f43c700ae997c284458fcc1d0dfc2e9a7 (diff)
parent06cf878471af02376dfcd02b9781982a89c27a2a (diff)
Merge branch 'master' of github.com:gogits/gogs
Conflicts: models/repo.go modules/base/tool.go serve.go
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/conf.go28
-rw-r--r--modules/base/tool.go26
2 files changed, 35 insertions, 19 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go
index 90b35476..0fb1ccdc 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -71,7 +71,7 @@ var Service struct {
ResetPwdCodeLives int
}
-func exeDir() (string, error) {
+func ExecDir() (string, error) {
file, err := exec.LookPath(os.Args[0])
if err != nil {
return "", err
@@ -244,7 +244,7 @@ func newNotifyMailService() {
func NewConfigContext() {
//var err error
- workDir, err := exeDir()
+ workDir, err := ExecDir()
if err != nil {
fmt.Printf("Fail to get work directory: %s\n", err)
os.Exit(2)
@@ -259,16 +259,11 @@ func NewConfigContext() {
Cfg.BlockMode = false
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
- if !com.IsFile(cfgPath) {
- fmt.Println("Custom configuration not found(custom/conf/app.ini)\n" +
- "Please create it and make your own configuration!")
- os.Exit(2)
-
- }
-
- if err = Cfg.AppendFiles(cfgPath); err != nil {
- fmt.Printf("Cannot load config file '%s'\n", cfgPath)
- os.Exit(2)
+ if com.IsFile(cfgPath) {
+ if err = Cfg.AppendFiles(cfgPath); err != nil {
+ fmt.Printf("Cannot load config file '%s'\n", cfgPath)
+ os.Exit(2)
+ }
}
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
@@ -276,7 +271,16 @@ func NewConfigContext() {
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
+
RunUser = Cfg.MustValue("", "RUN_USER")
+ curUser := os.Getenv("USERNAME")
+ if len(curUser) == 0 {
+ curUser = os.Getenv("USER")
+ }
+ if RunUser != curUser {
+ fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
+ os.Exit(2)
+ }
EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false)
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 4a8a124d..8f38d492 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -102,7 +102,10 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
// AvatarLink returns avatar link by given e-mail.
func AvatarLink(email string) string {
- return "/avatar/" + EncodeMd5(email)
+ if Service.EnableCacheAvatar {
+ return "/avatar/" + EncodeMd5(email)
+ }
+ return "http://1.gravatar.com/avatar/" + EncodeMd5(email)
}
// Seconds-based time units
@@ -483,15 +486,19 @@ func ActionIcon(opType int) string {
return "plus-circle"
case 5: // Commit repository.
return "arrow-circle-o-right"
+ case 6: // Create issue.
+ return "exclamation-circle"
default:
return "invalid type"
}
}
const (
- TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>`
- TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/%s/src/%s">%s</a> at <a href="/%s/%s">%s/%s</a>%s`
- TPL_COMMIT_REPO_LI = `<div><img id="gogs-user-avatar-commit" src="%s?s=16" alt="user-avatar" title="username"/> <a href="/%s/%s/commit/%s">%s</a> %s</div>`
+ TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s">%s</a>`
+ TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>%s`
+ TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s">%s</a> %s</div>`
+ TPL_CREATE_Issue = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a>
+<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
)
type PushCommits struct {
@@ -504,11 +511,12 @@ type PushCommits struct {
func ActionDesc(act Actioner, avatarLink string) string {
actUserName := act.GetActUserName()
repoName := act.GetRepoName()
+ repoLink := actUserName + "/" + repoName
branch := act.GetBranch()
content := act.GetContent()
switch act.GetOpType() {
case 1: // Create repository.
- return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName)
+ return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName)
case 5: // Commit repository.
var push *PushCommits
if err := json.Unmarshal([]byte(content), &push); err != nil {
@@ -516,13 +524,17 @@ func ActionDesc(act Actioner, avatarLink string) string {
}
buf := bytes.NewBuffer([]byte("\n"))
for _, commit := range push.Commits {
- buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n")
+ buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit[0], commit[0][:7], commit[1]) + "\n")
}
if push.Len > 3 {
buf.WriteString(fmt.Sprintf(`<div><a href="/%s/%s/commits/%s">%d other commits >></a></div>`, actUserName, repoName, branch, push.Len))
}
- return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, branch, branch, actUserName, repoName, actUserName, repoName,
+ return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink,
buf.String())
+ case 6: // Create issue.
+ infos := strings.SplitN(content, "|", 2)
+ return fmt.Sprintf(TPL_CREATE_Issue, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
+ avatarLink, infos[1])
default:
return "invalid type"
}