Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a list of commits from a repo, fails when there is no commits/default branch #278

Open
PolarizedIons opened this issue Oct 18, 2022 · 1 comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@PolarizedIons
Copy link

Running this query:

    public static readonly ICompiledQuery<GQLPagedResponse<Commit>> GetAllCommitsForRepo = new Query()
        .Repository(Var("repoName"), Var("repoOwner"))
        .DefaultBranchRef
        .Target
        .Cast<Octokit.GraphQL.Model.Commit>()
        .History(first: 100, after: Var("after"))
        .Select(connection => new GQLPagedResponse<Commit>
        {
            HasNextPage = connection.PageInfo.HasNextPage,
            EndCursor = connection.PageInfo.EndCursor,
            Items = connection.Nodes
                .Select(commit => new Commit
                {
                    Date = commit.CommittedDate,
                    Message = commit.Message,
                    Sha = commit.Oid,
                    RepoId = commit.Repository.DatabaseId ?? 0L,
                    UserId = commit.Committer.Select(x => x.User).Select(x => x.DatabaseId ?? 0L).SingleOrDefault(),
                    UserName = commit.Committer.Name,
                    UserEmail = commit.Committer.Email,
                })
                .ToList(),
        })
        .Compile();

Gives the stacktrace:

Unhandled exception. System.InvalidOperationException: Cannot access child value on Newtonsoft.Json.Linq.JValue.
   at Newtonsoft.Json.Linq.JToken.get_Item(Object key)
   at lambda_method14(Closure , JObject )
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.Deserialize[TResult](Func`2 deserialize, JObject data)
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.Deserialize[TResult](Func`2 deserialize, String data)
   at Octokit.GraphQL.Core.SimpleQuery`1.Runner.RunPage(CancellationToken cancellationToken)
   at Octokit.GraphQL.ConnectionExtensions.Run[T](IConnection connection, ICompiledQuery`1 query, Dictionary`2 variables, CancellationToken cancellationToken)
   at GithubStatsWorker.Worker.UpdateCommitStats() in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Worker.cs:line 46
   at GithubStatsWorker.Worker.UpdateRepoStats() in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Worker.cs:line 26
   at Program.<Main>$(String[] args) in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Program.cs:line 64
   at Program.<Main>(String[] args)

Trying to put a .SingleOrDefault() after the .DefaultBranchRef or .Target, gives the following exception:

Unhandled exception. System.TypeInitializationException: The type initializer for 'GithubStatsWorker.Queries' threw an exception.
 ---> System.NotImplementedException: The method or operation is not implemented.
   at Octokit.GraphQL.QueryableValueExtensions.SingleOrDefault[TValue](IQueryableValue`1 source)
   at GithubStatsWorker.Queries..cctor() in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Queries.cs:line 16
   --- End of inner exception stack trace ---
   at GithubStatsWorker.Worker.UpdateCommitStats() in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Worker.cs:line 46
   at GithubStatsWorker.Worker.UpdateRepoStats() in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Worker.cs:line 26
   at Program.<Main>$(String[] args) in /home/polarizedions/programming/GithubStats/GithubStatsWorker/Program.cs:line 64
   at Program.<Main>(String[] args)

Data returned from api: (screenshot from SimpleQuery.cs, RunPage method)
image

@nickfloyd nickfloyd added the bug label Oct 21, 2022
@nickfloyd
Copy link
Contributor

@PolarizedIons, thank you so much for reporting this ❤️ . We'll get it on our board for prioritization and try to reproduce the issue - thanks also for providing all the great info.

@nickfloyd nickfloyd added up-for-grabs Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented and removed up-for-grabs labels Oct 21, 2022
@nickfloyd nickfloyd moved this to 🆕 Triage in 🧰 Octokit Active Dec 5, 2022
@nickfloyd nickfloyd moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Dec 5, 2022
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

2 participants