Skip to content

Commit 9fe2361

Browse files
Merge pull request #38 from devtron-labs/licensing
feat: multiple repo support for release notes
2 parents 94a1dca + 175022e commit 9fe2361

8 files changed

Lines changed: 162 additions & 400 deletions

File tree

api/RestHandler.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
util "github.com/devtron-labs/central-api/client"
2222
"github.com/devtron-labs/central-api/common"
2323
"github.com/devtron-labs/central-api/pkg"
24+
"github.com/devtron-labs/central-api/pkg/bean"
2425
"github.com/gorilla/mux"
2526
"go.uber.org/zap"
2627
"io/ioutil"
@@ -134,8 +135,13 @@ func (impl *RestHandlerImpl) GetReleases(w http.ResponseWriter, r *http.Request)
134135
return
135136
}
136137
}
138+
repo := r.URL.Query().Get("repo")
139+
repository := bean.Oss
140+
if len(repo) > 0 {
141+
repository = bean.Repository(repo)
142+
}
137143
//will fetch all the releases from cache and later apply size and offset filter
138-
response, err := impl.releaseNoteService.GetReleases()
144+
response, err := impl.releaseNoteService.GetReleases(repository)
139145
if err != nil {
140146
impl.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
141147
return
@@ -148,6 +154,9 @@ func (impl *RestHandlerImpl) GetReleases(w http.ResponseWriter, r *http.Request)
148154
response = response[offset:]
149155
}
150156
}
157+
if len(response) == 0 {
158+
response = make([]*common.Release, 0)
159+
}
151160

152161
impl.WriteJsonResp(w, nil, response, http.StatusOK)
153162
return
@@ -178,7 +187,7 @@ func (impl *RestHandlerImpl) ReleaseWebhookHandler(w http.ResponseWriter, r *htt
178187
// validate event type
179188
eventType := r.Header.Get(impl.client.GitHubConfig.GitHubEventTypeHeader)
180189
impl.logger.Debugw("webhook event type header", "eventType : ", eventType)
181-
if len(eventType) == 0 && eventType != pkg.EventTypeRelease {
190+
if len(eventType) == 0 || eventType != bean.EventTypeRelease {
182191
impl.logger.Errorw("Event type not known ", eventType)
183192
impl.WriteJsonResp(w, err, nil, http.StatusBadRequest)
184193
return

api/Router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (r MuxRouter) Init() {
3838
r.Router.StrictSlash(true)
3939
//r.Router.Handle("/metrics", promhttp.Handler())
4040
r.Router.Path("/health").HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
41+
setupResponse(&writer, request)
4142
writer.Header().Set("Content-Type", "application/json")
4243
writer.WriteHeader(200)
4344
response := common.Response{}

client/GitHubClient.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ type GitConfig struct {
5858
}
5959

6060
type GitHubConfig struct {
61-
GitHubHost string `env:"GITHUB_HOST" envDefault:"https://github.com"`
62-
GitHubOrg string `env:"GITHUB_ORG" envDefault:""`
63-
GitHubToken string `env:"GITHUB_TOKEN" envDefault:""`
64-
GitHubRepo string `env:"GITHUB_REPO" envDefault:"devtron"`
61+
GitHubHost string `env:"GITHUB_HOST" envDefault:"https://github.com"`
62+
GitHubOrg string `env:"GITHUB_ORG" envDefault:""`
63+
GitHubToken string `env:"GITHUB_TOKEN" envDefault:""`
64+
GitHubRepo []string `env:"GITHUB_REPO" envDefault:"devtron" envSeparator:","`
6565

6666
GitHubWebhookSecret string `env:"GITHUB_WEBHOOK_SECRET" envDefault:""`
6767
GitHubEventTypeHeader string `env:"GITHUB_EVENT_TYPE_HEADER" envDefault:"X-GitHub-Event"`

0 commit comments

Comments
 (0)