Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
GitlabRSSSync
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
GitlabRSSSync
Commits
ebf265fd
Commit
ebf265fd
authored
6 years ago
by
Adam Harrison-Fuller
Browse files
Options
Downloads
Patches
Plain Diff
Tidyup
Signed-off-by:
Adam Harrison-Fuller
<
adam@adamhf.io
>
parent
0209b248
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
main.go
+14
-13
14 additions, 13 deletions
main.go
with
15 additions
and
14 deletions
README.md
+
1
−
1
View file @
ebf265fd
...
...
@@ -8,7 +8,7 @@ A SQLite DB is used to store the GUID/FeedID combination which is checked when a
In addition we also add the RSS feed's item GUID at the bottom of the issue description. Before synchronising an RSS item
we run an issue search in the associated project, if we dont find the GUID in any issue we assume its not already been created.
This helps to guard against scenarios where you lose the SQLite DB and dont want RSS items reduplicating into Gitlab.
If found in Gitlab it is marked as syncronised in the local database as well as printing an link to the existing issue(s) to stdout.
If found in Gitlab it is marked as sync
h
ronised in the local database as well as printing an link to the existing issue(s) to stdout.
## Limiting what is initially synced.
Each feed entry in the config file can have an "added_since" property set. This is used to only sync RSS items that have a
...
...
This diff is collapsed.
Click to expand it.
main.go
+
14
−
13
View file @
ebf265fd
...
...
@@ -49,10 +49,10 @@ type EnvValues struct {
GitlabAPIKey
string
}
func
hasExistingGitlabIssue
(
guid
string
,
projectID
int
,
gitlabClient
*
gitlab
.
Client
)
bool
{
func
hasExistingGitlabIssue
(
guid
string
,
projectID
int
,
gitlabClient
*
gitlab
.
Client
)
bool
{
searchOptions
:=
&
gitlab
.
SearchOptions
{
Page
:
1
,
PerPage
:
10
,
Page
:
1
,
PerPage
:
10
,
}
issues
,
_
,
err
:=
gitlabClient
.
Search
.
IssuesByProject
(
projectID
,
guid
,
searchOptions
)
if
err
!=
nil
{
...
...
@@ -110,7 +110,8 @@ func (feed Feed) checkFeed(db *gorm.DB, gitlabClient *gitlab.Client) {
}
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
)
fmt
.
Printf
(
"Ignoring %s as its date is < the specified AddedSince (Item: %s vs AddedSince: %s)
\n
"
,
item
.
Title
,
time
,
feed
.
AddedSince
)
continue
}
...
...
@@ -136,15 +137,16 @@ func (feed Feed) checkFeed(db *gorm.DB, gitlabClient *gitlab.Client) {
CreatedAt
:
time
,
}
//fmt.Println(issueOptions)
_
,
_
,
err
:=
gitlabClient
.
Issues
.
CreateIssue
(
feed
.
GitlabProjectID
,
issueOptions
)
if
err
!=
nil
{
if
_
,
_
,
err
:=
gitlabClient
.
Issues
.
CreateIssue
(
feed
.
GitlabProjectID
,
issueOptions
);
err
!=
nil
{
fmt
.
Printf
(
"Unable to create Gitlab issue for %s
\n
%s
\n
"
,
feed
.
Name
,
err
)
}
else
{
fmt
.
Printf
(
"Created Gitlab Issue '%s' in project: %d'
\n
"
,
item
.
Title
,
feed
.
GitlabProjectID
)
db
.
Create
(
&
SyncedItems
{
UUID
:
item
.
GUID
,
Feed
:
feed
.
ID
})
issuesCreatedCounter
.
Inc
()
continue
}
if
err
:=
db
.
Create
(
&
SyncedItems
{
UUID
:
item
.
GUID
,
Feed
:
feed
.
ID
})
.
Error
;
err
!=
nil
{
fmt
.
Printf
(
"Unable to persist in %s DB: %s
\n
"
,
item
.
Title
,
err
)
continue
}
issuesCreatedCounter
.
Inc
()
fmt
.
Printf
(
"Created Gitlab Issue '%s' in project: %d'
\n
"
,
item
.
Title
,
feed
.
GitlabProjectID
)
}
}
...
...
@@ -156,8 +158,7 @@ func readConfig(path string) *Config {
log
.
Fatalln
(
err
)
}
err
=
yaml
.
Unmarshal
(
data
,
config
)
if
err
!=
nil
{
if
err
=
yaml
.
Unmarshal
(
data
,
config
);
err
!=
nil
{
fmt
.
Printf
(
"Unable to parse config YAML
\n
%s
\n
"
,
err
)
panic
(
err
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment