0

I'm trying to place some config files under version control using Github. The ONLY way to get these particular config files is via a GET request to the hosting server. Server responds with a .zip file.

.zip file structure looks similar to:

|-Folder1
--|-File1.json
--|-File2.json
--|-Pic1.jpg
|-Folder2
--|-File3.json
--|Folder3
----|Pic2.jpg
|-File4.json
|-File5.json

As you can see, its a mix of text and binary files. Also has a nested folder structure.

I need to:

  • Commit this .zip file to Github using the Github REST API (no problem there)
  • But BEFORE committing, how can I programmatically extract the folders and files (LEAVING THE FOLDER STRUCTURE IN PLACE)
  • Commit the results to Github

I've checked the question/solutions mentioned here, but they don't quite match/are a few years old.

Anyone have a workflow for doing this? I have to imagine SOMEONE has come across similar requirements.

SeaDude
  • 3,725
  • 6
  • 31
  • 68

1 Answers1

0

I ended up using Power Automate to handle this.

Basically,

  • GET .zip file
  • Add it to OneDrive for Business
  • Extract it there (folder structure is "flattened", but luckily OneDrive "keeps" it by renaming each file)
  • Example: Folder1/File1.json in the .zip becomes Folder1_File1.json once extracted
  • When committing to Github via api, I just did a replace for the filename; INCLUDING the / as part of the path.
  • Example URL: https://api.github.com/repos/SeaDude/replace(items('FOR_EACH_app')?['properties']?['DisplayName'], ' ', '-')/contents/replace(items('FOR_EACH_source_file_2')?['Name'],'_','/')
    • Apparently, you can specify an empty (or non-empty) path as part of an API commit. If the directory is empty, Github will create it!
SeaDude
  • 3,725
  • 6
  • 31
  • 68