~emersion/hottub

513d8b05e2014c2aae6c24e4d1170efc2723c3a4 — Simon Ser 8 months ago 8081eac
Fix link to installation settings for GitHub orgs
3 files changed, 20 insertions(+), 9 deletions(-)

M db.go
M main.go
M templates/post-install.html
M db.go => db.go +1 -0
@@ 17,6 17,7 @@ var ErrNotFound = fmt.Errorf("resource not found in DB")
type Installation struct {
	ID        int64     `json:"-"`
	Owner     string    `json:"owner"`
	Org       string    `json:"org,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	SrhtToken string    `json:"srht_token,omitempty"`
}

M main.go => main.go +18 -8
@@ 207,16 207,25 @@ func main() {
			return
		}

		var installSettingsURL string
		if installation != nil {
			if installation.Org != "" {
				installSettingsURL = fmt.Sprintf("https://github.com/organizations/%v/settings/installations/%v", installation.Org, id)
			} else {
				installSettingsURL = fmt.Sprintf("https://github.com/settings/installations/%v", id)
			}
		}

		data := struct {
			Pending        bool
			Done           bool
			SrhtGrants     string
			InstallationID int64
			Pending            bool
			Done               bool
			SrhtGrants         string
			InstallSettingsURL string
		}{
			Pending:        installation == nil,
			Done:           installation != nil && installation.SrhtToken != "",
			SrhtGrants:     srhtGrants,
			InstallationID: id,
			Pending:            installation == nil,
			Done:               installation != nil && installation.SrhtToken != "",
			SrhtGrants:         srhtGrants,
			InstallSettingsURL: installSettingsURL,
		}
		if err := tpl.ExecuteTemplate(w, "post-install.html", &data); err != nil {
			panic(err)


@@ 249,6 258,7 @@ func main() {
					ID:        *event.Installation.ID,
					CreatedAt: time.Now(),
					Owner:     event.Sender.GetLogin(),
					Org:       event.GetOrg().GetLogin(),
				})
			case "deleted":
				err = db.DeleteInstallation(*event.Installation.ID)

M templates/post-install.html => templates/post-install.html +1 -1
@@ 10,7 10,7 @@
{{ else if .Done }}
	<p>Installation complete!</p>
	<p>
		To manage the installation, <a href="https://github.com/settings/installations/{{ .InstallationID }}">head over to GitHub settings</a>.
		To manage the installation, <a href="{{ .InstallSettingsURL }}">head over to GitHub settings</a>.
	</p>
{{ else }}
	<p>