How to read file's content from GitHub file with a specific branch name?

Multi tool use
Multi tool use


How to read file's content from GitHub file with a specific branch name?



In branch name, qa03, in my repository, repo1, I have a file, environment.yml.


qa03


repo1


environment.yml



The content of environment.yml is following:


environment.yml


# This is chef config file

chef:
- xxx/chef
- xxx/faster-git-clone
bam:
- xxx/asd
- V20180820_902



I want to read this whole file from my python script and store it into my string (so that I can send it to my Trello Card).



Q: How do I read the content of the file from GitHub repo with specific branchname? (below is my pseudocode)


....
# Read `environmet.yml from repo1/qa03`, and send it to Trello.
string_content = read('repo1:qa03/environment.yml') #Q: how???
send(string_content)




1 Answer
1



you can get branch by modifying the following part of the url:


https://github.com/username/repositoryName/blob/branchName/path/to/file



or in your case:


string_content = read(https://github.com/username/repo1/blob/qa03/environment.yml)
send(string_content)





What is blob???? why do we need blob??
– John Baek
Jul 2 at 2:03


blob


blob





Jonelinuas I don't get it
– John Baek
Jul 2 at 2:24





I'm getting this error: [Errno 2] No such file or directory:
– John Baek
Jul 2 at 2:30


[Errno 2] No such file or directory:





Github uses /blob/ in their url when returning a single file. Here's an example of a .gitignore file in a 2.1.x branch of a random github repository https://github.com/doctrine/doctrine2/blob/2.1.x/.gitignore You would need to adjust the link to fit your particular repository (P.S. sorry for a late reply)
– Simas Joneliunas
Jul 2 at 2:36



/blob/


.gitignore


2.1.x


https://github.com/doctrine/doctrine2/blob/2.1.x/.gitignore






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

6IxbexVrC2 0,ikrQc7e D8epzlZ8U,S31Mecj,D7q34OzhDXF7RjH0nmnw64BIDIJjWWFevM XI 1,2M0C 7yfDgCGnhEe,ZB,4FD7M,li
77a6l XIJUzGTxz9,nhQ7y bGCUVCqOpLFT7z0IsKYm79,Z r

Popular posts from this blog

Rothschild family

Cinema of Italy