Reputation: 37
I need to find and list the branches that are
from multiple projects and multiple repositories with single script from bit bucket and also the report should be printed in this format
project name: repo name: branch name: last commit date: author name:
I tried this in shell script
#!/bin/sh
echo "Merged branches"
for branch in `git branch -r --merged | grep -v HEAD`;
do echo -e `git log --no-merges -n 1 --format="%ci, %cr, %an, %ae, " $branch
| head -n 1` \\t$branch; done | sort -r
echo ""
echo "Not merged branches"
for branch in `git branch -r --no-merged | grep -v HEAD`;
do echo -e `git log --no-merges -n 1 --format="%ci, %cr, %an, %ae, " $branch |
head -n 1` \\t$branch; done | sort -r
by using these i can fetch only in that particular repo. how to list all the projects and repos and execute these git commands?
Upvotes: 0
Views: 3431
Reputation: 4202
Bitbucket has some well written api documentation.
Within this documentation one can find the resource: /repositories
As quoted from their documentation this endpoint:
Returns a paginated list of all public repositories. This endpoint also supports filtering and sorting of the results. See filtering and sorting for more details.
These are all public repositories you own. Within this response there should be a git url.
You can parse the json and retrieve all git urls of every repository and store them within a variabele.
Then loop through the git repositories urls and clone each one of them by the command: git clone --recurse-submodules GIT_URL_HERE
The --recurse-submodules
option is used here since if there are any submodules we want to get them aswell!
After all repo's are cloned succesfully go into each directory by using the cd DIRECTORY
command.
Within these directories one can list the branches.
git branch --merged
lists branches merged into HEAD (i.e. tip of current branch)
git branch --no-merged
lists branches that have not been merged
Upvotes: 1