Tool to calculate the average time that takes for a GitHub pull request to get merged
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I'm learning go, and this is my first attempt at a command line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or repository.
The algorithm follows a very simple approach:
- Get all the repositories for an organisation.
- For each repository, get all the
closed
pull requests. - Calculate the average time using
merged_at
andcreated_at
of each pull request.
For large organisations/projects, step 2 can take a long time, specially if it can't get all the pull requests from a single result page. So I want to execute that part concurrently.
Here's the part of the code that does that: GitHub
c := make(chan Result, len(repos))
var wg sync.WaitGroup
for _, repo := range repos
wg.Add(1)
go func(val Repository)
if cmd.Debug
fmt.Printf("Executing goroutine for value: %s", val.Name)
pullRequests, err := getPullRequests(ctx, client, val)
c <- ResultPullRequests: pullRequests, Err: err
wg.Done()
(repo)
wg.Wait()
close(c)
timeAccumulator := float64(0)
prAccumulator := int64(0)
var cmdErr error
for result := range c
pullRequests, err := result.PullRequests, result.Err
if err != nil
cmdErr = err
break
for _, pullRequest := range pullRequests
if pullRequest.GetMergedAt().IsZero()
continue
delta := pullRequest.GetMergedAt().Sub(pullRequest.GetCreatedAt()).Hours()
timeAccumulator += delta
prAccumulator++
if cmd.Debug
fmt.Printf("PR: %snCreated at: %vnMerged at:%vnDelta in hours: %fn", pullRequest.GetTitle(), pullRequest.GetCreatedAt(), pullRequest.GetMergedAt(), delta)
It works, but I'd like to get some feedback about the WaitGroup
usage. It does feel that I don't need it here, because looping over range c
would take results until the channel is closed, it's just not clear to me when I should really close the channel without a WaitGroup.
And of course any other feedback is really welcomed!
api concurrency go git
add a comment |Â
up vote
2
down vote
favorite
I'm learning go, and this is my first attempt at a command line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or repository.
The algorithm follows a very simple approach:
- Get all the repositories for an organisation.
- For each repository, get all the
closed
pull requests. - Calculate the average time using
merged_at
andcreated_at
of each pull request.
For large organisations/projects, step 2 can take a long time, specially if it can't get all the pull requests from a single result page. So I want to execute that part concurrently.
Here's the part of the code that does that: GitHub
c := make(chan Result, len(repos))
var wg sync.WaitGroup
for _, repo := range repos
wg.Add(1)
go func(val Repository)
if cmd.Debug
fmt.Printf("Executing goroutine for value: %s", val.Name)
pullRequests, err := getPullRequests(ctx, client, val)
c <- ResultPullRequests: pullRequests, Err: err
wg.Done()
(repo)
wg.Wait()
close(c)
timeAccumulator := float64(0)
prAccumulator := int64(0)
var cmdErr error
for result := range c
pullRequests, err := result.PullRequests, result.Err
if err != nil
cmdErr = err
break
for _, pullRequest := range pullRequests
if pullRequest.GetMergedAt().IsZero()
continue
delta := pullRequest.GetMergedAt().Sub(pullRequest.GetCreatedAt()).Hours()
timeAccumulator += delta
prAccumulator++
if cmd.Debug
fmt.Printf("PR: %snCreated at: %vnMerged at:%vnDelta in hours: %fn", pullRequest.GetTitle(), pullRequest.GetCreatedAt(), pullRequest.GetMergedAt(), delta)
It works, but I'd like to get some feedback about the WaitGroup
usage. It does feel that I don't need it here, because looping over range c
would take results until the channel is closed, it's just not clear to me when I should really close the channel without a WaitGroup.
And of course any other feedback is really welcomed!
api concurrency go git
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm learning go, and this is my first attempt at a command line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or repository.
The algorithm follows a very simple approach:
- Get all the repositories for an organisation.
- For each repository, get all the
closed
pull requests. - Calculate the average time using
merged_at
andcreated_at
of each pull request.
For large organisations/projects, step 2 can take a long time, specially if it can't get all the pull requests from a single result page. So I want to execute that part concurrently.
Here's the part of the code that does that: GitHub
c := make(chan Result, len(repos))
var wg sync.WaitGroup
for _, repo := range repos
wg.Add(1)
go func(val Repository)
if cmd.Debug
fmt.Printf("Executing goroutine for value: %s", val.Name)
pullRequests, err := getPullRequests(ctx, client, val)
c <- ResultPullRequests: pullRequests, Err: err
wg.Done()
(repo)
wg.Wait()
close(c)
timeAccumulator := float64(0)
prAccumulator := int64(0)
var cmdErr error
for result := range c
pullRequests, err := result.PullRequests, result.Err
if err != nil
cmdErr = err
break
for _, pullRequest := range pullRequests
if pullRequest.GetMergedAt().IsZero()
continue
delta := pullRequest.GetMergedAt().Sub(pullRequest.GetCreatedAt()).Hours()
timeAccumulator += delta
prAccumulator++
if cmd.Debug
fmt.Printf("PR: %snCreated at: %vnMerged at:%vnDelta in hours: %fn", pullRequest.GetTitle(), pullRequest.GetCreatedAt(), pullRequest.GetMergedAt(), delta)
It works, but I'd like to get some feedback about the WaitGroup
usage. It does feel that I don't need it here, because looping over range c
would take results until the channel is closed, it's just not clear to me when I should really close the channel without a WaitGroup.
And of course any other feedback is really welcomed!
api concurrency go git
I'm learning go, and this is my first attempt at a command line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or repository.
The algorithm follows a very simple approach:
- Get all the repositories for an organisation.
- For each repository, get all the
closed
pull requests. - Calculate the average time using
merged_at
andcreated_at
of each pull request.
For large organisations/projects, step 2 can take a long time, specially if it can't get all the pull requests from a single result page. So I want to execute that part concurrently.
Here's the part of the code that does that: GitHub
c := make(chan Result, len(repos))
var wg sync.WaitGroup
for _, repo := range repos
wg.Add(1)
go func(val Repository)
if cmd.Debug
fmt.Printf("Executing goroutine for value: %s", val.Name)
pullRequests, err := getPullRequests(ctx, client, val)
c <- ResultPullRequests: pullRequests, Err: err
wg.Done()
(repo)
wg.Wait()
close(c)
timeAccumulator := float64(0)
prAccumulator := int64(0)
var cmdErr error
for result := range c
pullRequests, err := result.PullRequests, result.Err
if err != nil
cmdErr = err
break
for _, pullRequest := range pullRequests
if pullRequest.GetMergedAt().IsZero()
continue
delta := pullRequest.GetMergedAt().Sub(pullRequest.GetCreatedAt()).Hours()
timeAccumulator += delta
prAccumulator++
if cmd.Debug
fmt.Printf("PR: %snCreated at: %vnMerged at:%vnDelta in hours: %fn", pullRequest.GetTitle(), pullRequest.GetCreatedAt(), pullRequest.GetMergedAt(), delta)
It works, but I'd like to get some feedback about the WaitGroup
usage. It does feel that I don't need it here, because looping over range c
would take results until the channel is closed, it's just not clear to me when I should really close the channel without a WaitGroup.
And of course any other feedback is really welcomed!
api concurrency go git
edited Feb 6 at 18:18
200_success
123k14143401
123k14143401
asked Feb 6 at 8:55
Ruenzuo
1113
1113
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186896%2ftool-to-calculate-the-average-time-that-takes-for-a-github-pull-request-to-get-m%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password