Git Product home page Git Product logo

Comments (15)

 avatar commented on July 23, 2024 1

A last idea:
Maybe the SHA of the file content could be uploaded to confluence too. Either as additional file, or as postfix in the upload comment.

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024 1

Actually that's not a bad idea at all. It could be in the update comment like you suggested, or perhaps as part of the page itself, maybe in a hidden field.

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024 1

1.1.2 is up!

from md2cf.

 avatar commented on July 23, 2024

I have a prototype up running, which can skip some pages.

new definition in api.py:

    def get_body(self, page_id):
        body = None
        try:
            params = {
                #"id": page_id,
                "expand": "body.storage"
            }
            result = self.api.content(page_id).get(params=params)
            body = result["body"]["storage"]["value"]
        except:
            pass
        return body

upsert_page in __main__.py gets following change:

        print(f"Updating page: {page.title}")
        existing_body = confluence.get_body(existing_page.id)
        if existing_body.strip("\n") != page.body.strip("\n"): # strip to remove the trailing linebreak from the generated page
            confluence.update_page(
                page=existing_page,
                body=page.body,
                parent_id=page.parent_id,
                update_message=message,
            )
        else:
            print(f"  Page already up to date: {page.title}")

When the page is simple enough this works.

But I found some further differences, which need to escaped.

  • For example quotes: the one from the server of course has " in it, the generated has " in it. => can be managed
  • Another difference are the code macros: the version on the server has <ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro-id="bfba7d1f-dc91-4acb-9165-e28209c0e32d"> in it. ac:schema-version and ac:macro-id are not part of the generated document. The schema-version is probably a quick adaption of block_code. But I don't think we should upload a generated ID onto the server.
    => So we probably have to parse the complete xml for differences and ignore these IDs. Urghs. I hate xml parsing.

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

Oh, that's actually a very good point. We have two options:

  • Keep a local file with the SHA1 of every uploaded page, and only upsert if it's different
  • Do some parsing like you suggested, and compare the live page to the one that's about to be uploaded

I feel like the first solution would be tidier, but it requires some persistent storage, which is not always an option (especially in CI pipelines). Hmmm.

Another thing to keep in mind is that the page content might have stayed the same, but an attachment might have been updated.

from md2cf.

 avatar commented on July 23, 2024

Yeah, local files would unfortunately not be ideal for CI (as for our use case).

The attachment problem was indeed skipped by me (because we don't have many, so they're not the main problem).

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

I just implemented this in v1.1.0. You can pass the --only-changed option, and it will append the hash of the page/attachment at the end of the update comment and compare it :) Of course this will still trigger changes everywhere the first time you run it, as it needs to add the hash to everything, but after that you should be golden.

Let me know if it works alright for you!

from md2cf.

marci4 avatar marci4 commented on July 23, 2024

Hey,
Thank you very much for implementing it.

Gonna test it right away.

Best regards,
Marcel

from md2cf.

marci4 avatar marci4 commented on July 23, 2024

Hello @iamjackg,

thank you very much for implementing this.
I found a small bug, when the command line option -m is used, the old hash cannot be determined and the page will not be skipped.

Could you maybe take a look at this? Thank you very much!

Best regards,
Marcel

EDIT:
StR (Upload contains one file, nothing special)
Create new page with -m "Automatic upload of documentation" --only-changed --skip-empty Upload
<< Creating new page: md2cf
Rerun same command:
<< Updating page: md2cf

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

I'll take a look tonight :)

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

Quick question, does the page you're trying to upload happen to be empty? And what version of Confluence are you running? Did you recently update it?

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

I've found the issue btw, I'm about to release a fix. I'm only asking because I'm testing a newer version of Confluence (7.14.1), and it seems like it already doesn't update pages whose content did not change.

from md2cf.

marci4 avatar marci4 commented on July 23, 2024

Quick question, does the page you're trying to upload happen to be empty? And what version of Confluence are you running? Did you recently update it?

I created a fresh page for this test. But it also happens with existing pages.
Confluence version is 7.13.3.
Last update was a month ago, I think

Gonna test 1.1.2 right away. Thank you for the quick fix.

from md2cf.

marci4 avatar marci4 commented on July 23, 2024

1.1.2 looks good, thank you very much!

from md2cf.

iamjackg avatar iamjackg commented on July 23, 2024

Perfect, I'm gonna close this then. Cheers!

from md2cf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.