Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added update-if-older-than option #489

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const (
version = "10.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rebase and keep the version?

version = "10.0.1"
usage = "A tool for updating Atlassian Confluence pages from markdown."
description = `Mark is a tool to update Atlassian Confluence pages from markdown. Documentation is available here: https://github.com/kovetskiy/mark`
)
Expand Down Expand Up @@ -188,6 +188,12 @@ var flags = []cli.Flag{
TakesFile: true,
EnvVars: []string{"MARK_INCLUDE_PATH"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "update-if-older-than",
Value: "",
Usage: "Update the page only if the last update is older than the specified date.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the format here in which mark expects the date to be in?

TakesFile: false,
}),
}

func main() {
Expand Down Expand Up @@ -444,6 +450,20 @@ func processFile(
// helps mitigate a 409 conflict that can occur when attempting
// to update a page just after it was created.
time.Sleep(1 * time.Second)
} else {
updateIfOlderThan := cCtx.String("update-if-older-than")
if updateIfOlderThan != "" {
checkTime, err := time.Parse(time.RFC3339Nano, updateIfOlderThan)
if err != nil {
log.Fatalf(err, "unable to parse update-if-older-than date: %s", updateIfOlderThan)
}
log.Debugf(nil, "Checking if page was updated after %s, page last update is %s", checkTime, page.Version.When)
if page.Version.When.After(checkTime) {
log.Infof(nil, "Page was updated after %s, skipping update", checkTime)
return page
}
}

}

target = page
Expand Down
4 changes: 3 additions & 1 deletion pkg/confluence/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"mime/multipart"
"net/http"
"strings"
"time"

"github.com/kovetskiy/gopencils"
"github.com/kovetskiy/lorg"
Expand Down Expand Up @@ -48,7 +49,8 @@ type PageInfo struct {
Type string `json:"type"`

Version struct {
Number int64 `json:"number"`
Number int64 `json:"number"`
When time.Time `json:"when"`
} `json:"version"`

Ancestors []struct {
Expand Down