1

hope you can help me with this one.. A simple example will do.. I have a Mule project in a github repo and I need to update the pom.xml automatically.. I know could "mimic" what we humans do with python3 by cloning the repo down, update the file and push the changes back to github.. (using the "os" module) but In this case I cannot clone the repo..(the storage is not reliable) I see that there are several github modules for python I cant get it to work (lack of knowledge I guess).. If anyone can show me simply how to update a line in the file (replace a string for example) .. that would be a great starting point for me.

sample scenario: file: https://github.com/USERNAME/PROJECT_NAME/blob/master/pom.xml

I need to update line <artifactId>template</artifactId> (in this case, line 6) with the line <artifactId>actual_project_name</artifactId>

Thanks!

Santos
  • 177
  • 1
  • 1
  • 15
  • 2
    what have you already tried? – Insula Jan 20 '21 at 13:24
  • 2
    This could help: https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents – Diego Jan 20 '21 at 13:46
  • I tried to use the OS module and simply using clone clone, commit and push before... Then I was told to try not to mimic human behaviour and see if I can pull this off interacting directly with the github api.. I found stuff like PyGithub that may do the trick but I can't follow along.. maybe I'm missing something, that is why I was asking for someone who have a better understanding... for a starting point.. a simple demo snippet that I can use to build on top.. thanks for the question! – Santos Jan 20 '21 at 13:55
  • Thanks for the link Diego, I will take a look... in the meantime I found [this](https://www.youtube.com/watch?v=xfYDy4nSc28) (videos always help) .. this guy uses the pyGithub to login, create and update a file.. the only thing that I noticed is that when it update the file, it replace the entire content with the new one.. but is a start. – Santos Jan 20 '21 at 14:18
  • I made some progress with pygithub, I shared my code [here](https://github.com/santiagomoneta/pygithub-example) .. So now is to set up some logic to update the content of a file, not replace it completely.. any sample is welcome. Thanks for the pointers! – Santos Jan 20 '21 at 15:33

1 Answers1

2

I was able to "crack it" ... (just needed time and try/error)

I shared a simple script to do basic tasks using the pyGithub module, included partially update a file. Hopefully this will help anyone on the same situation and will be a nice starting point. cheers!!

REPO LINK: https://github.com/santiagomoneta/pygithub-example

Cheers!

Santos
  • 177
  • 1
  • 1
  • 15