From be32f4a3777d92ba90901fa2e9d50192eefad5c4 Mon Sep 17 00:00:00 2001 From: Adam Harrison-Fuller <adam@adamhf.io> Date: Wed, 27 Mar 2019 16:40:46 +0000 Subject: [PATCH] Adding added_since Signed-off-by: Adam Harrison-Fuller <adam@adamhf.io> --- config.yaml | 2 ++ main.go | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config.yaml b/config.yaml index 67a6180..cf3df4b 100644 --- a/config.yaml +++ b/config.yaml @@ -10,6 +10,7 @@ feeds: feed_url: https://cloud.google.com/feeds/kubernetes-engine-release-notes.xml name: GKE release notes gitlab_project_id: 11494338 + added_since: "2019-03-27T15:00:00Z" labels: - GKEReleaseNotes - Needs/Triage @@ -17,6 +18,7 @@ feeds: feed_url: https://cloud.google.com/feeds/kubernetes-engine-security-bulletins.xml name: GKE Security Updates gitlab_project_id: 11494338 + added_since: "2019-03-27T15:00:00Z" labels: - GKESecurityUpdates - Needs/Triage diff --git a/main.go b/main.go index 7218b18..ad42ca4 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ type Feed struct { Name string GitlabProjectID int `yaml:"gitlab_project_id"` Labels []string + AddedSince time.Time `yaml:"added_since"` } type SyncedItems struct { @@ -59,13 +60,11 @@ func (feed Feed) checkFeed(db *gorm.DB, gitlabClient *gitlab.Client) { var newArticle []*gofeed.Item var oldArticle []*gofeed.Item for _, item := range rss.Items { - found := !db.First(&SyncedItems{}, "feed = ? AND uuid = ?", feed.ID, item.GUID).RecordNotFound() if found == true { oldArticle = append(oldArticle, item) } else { newArticle = append(newArticle, item) - } } @@ -90,11 +89,16 @@ func (feed Feed) checkFeed(db *gorm.DB, gitlabClient *gitlab.Client) { time = item.PublishedParsed } + if time.Before(feed.AddedSince) { + fmt.Printf("Ignoring %s as its date is < the specified AddedSince (Item: %s vs AddedSince: %s) \n", item.Title, time, feed.AddedSince) + continue + } + issueOptions := &gitlab.CreateIssueOptions{ Title: gitlab.String(item.Title), Description: gitlab.String(body), Labels: feed.Labels, - CreatedAt: time, + CreatedAt: time, } //fmt.Println(issueOptions) @@ -120,12 +124,14 @@ func readConfig(path string) *Config { err = yaml.Unmarshal(data, config) if err != nil { - log.Fatalln("Unable to parse config YAML \n ") + fmt.Printf("Unable to parse config YAML \n %s \n", err) + panic(err) } + return config } -func initialise(env EnvValues) (db *gorm.DB, client *gitlab.Client, config *Config){ +func initialise(env EnvValues) (db *gorm.DB, client *gitlab.Client, config *Config) { gaugeOpts := prometheus.GaugeOpts{ Name: "last_run_time", Help: "Last Run Time in Unix Seconds", @@ -156,7 +162,7 @@ func initialise(env EnvValues) (db *gorm.DB, client *gitlab.Client, config *Conf func main() { env := readEnv() db, gitlabClient, config := initialise(env) - //defer db.Close() + defer db.Close() go func() { for { -- GitLab