|
|
@@ -1,15 +1,16 @@
|
|
|
package status
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
+ "io"
|
|
|
"net/http"
|
|
|
- "strings"
|
|
|
|
|
|
- "github.com/mmcdole/gofeed"
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
"github.com/porter-dev/porter/api/server/shared"
|
|
|
"github.com/porter-dev/porter/api/server/shared/apierrors"
|
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
|
+ "github.com/porter-dev/porter/api/types"
|
|
|
)
|
|
|
|
|
|
type GetGithubStatusHandler struct {
|
|
|
@@ -26,23 +27,34 @@ func NewGetGithubStatusHandler(
|
|
|
}
|
|
|
|
|
|
func (c *GetGithubStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
- fp := gofeed.NewParser()
|
|
|
- feed, err := fp.ParseURL("https://www.githubstatus.com/history.rss")
|
|
|
+ resp, err := http.Get("https://www.githubstatus.com/api/v2/incidents/unresolved.json")
|
|
|
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("error fetching github status RSS: %w", err)))
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("error fetching github incidents: %w", err)))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if len(feed.Items) > 0 {
|
|
|
- description := feed.Items[0].Description
|
|
|
- link := feed.Items[0].Link
|
|
|
+ defer resp.Body.Close()
|
|
|
|
|
|
- if !strings.Contains(description, "This incident has been resolved") {
|
|
|
- // ongoing incident
|
|
|
- c.WriteResult(w, r, link)
|
|
|
- return
|
|
|
- }
|
|
|
+ data, err := io.ReadAll(resp.Body)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("error reading github incidents: %w", err)))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var incidents types.GithubUnresolvedIncidents
|
|
|
+
|
|
|
+ err = json.Unmarshal(data, &incidents)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("error unmarshalling json: %w", err)))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(incidents.Incidents) > 0 {
|
|
|
+ c.WriteResult(w, r, fmt.Sprintf("https://www.githubstatus.com/incidents/%s", incidents.Incidents[0].ID))
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
c.WriteResult(w, r, "no active incidents")
|