LIbGit2Sharp: list all the pull request's authors - github

Using the LibGit2Sharp library, I'm trying to list all authors of pull requests on the master branch of a repo. I don't see anything in the docs, intellisense, or through search that has an example of this. Any pointers??
I have constructed the code below, but I'm getting the following error message An unhandled exception of type 'LibGit2Sharp.RepositoryNotFoundException' occurred in LibGit2Sharp.dll. Browsing around, it seems that the references I find are to local cloned repos and not remote repositories.
static void Main(string[] args)
{
var co = new CloneOptions();
co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
{
Username = "username",
Password = "password"
};
var clonedRepoPath = Repository.Clone(url, "path/to/clone", co);
using (var repo = new Repository(clonedRepoPath))
{
foreach (Commit commit in repo.Commits)
{
Console.WriteLine(commit.Author.Name);
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
}

...list all the pull requests ......
First of all, “pull requests” are a DVCS workflow method, and are not a feature of git. Most people inherently, and incorrectly, think it is a part of git. Github.com (and others) have a pull request workflow system that includes items such as a git merge, topic discussion, continuous integration (CI) hooks, issue referencing, user permissions, etc.. with ONLY the git merge being actually from the git DVCS.
That said, within a git repository, Github-style pull requests are merges between two commit-ishs (usually merging from topic branch to a master branch, but this is not a requirement) and thus the 'pull request' commit have two parents.
FYI: For merges that have three(+) parents, see this answer
So back to your question:
list the authors of all the pull requests on the master branch of a repo
That statement becomes the following git cmd:
git log master --merges --pretty=format:"%an %s" becomes:
In translating that to libgit2sharp:
// find the master branch in the repo
var masterBranch = repo.Branches.Single (branch => branch.FriendlyName == "master");
// Filter the branch's commits to ones that are merges
var mergeList = masterBranch.Commits.Where (p => p.Parents.Count () >= 2);
// Display the merge commits (pull requests)
foreach (Commit commit in mergeList)
{
Console.WriteLine("{0}\t{1}", commit.Author.Name, commit.MessageShort);
}
Example output of a github repo that uses pull requests:
João Matos Merge pull request #1966 from angeloc/master
Zoltan Varga Merge pull request #1965 from akoeplinger/fix-flaky-test
João Matos Merge pull request #1963 from angeloc/patch-1
Rodrigo Kumpera Merge pull request #1912 from ludovic-henry/threadpool-managed-asyncresult
Zoltan Varga Merge pull request #1959 from alexrp/master
Zoltan Varga Merge pull request #1958 from rolfbjarne/aot-error-reporting
Marek Safar Merge pull request #1955 from LogosBible/servicepoint_nre
...
Update:
Based upon the comment, libgit2sharp is not going to give the user what they want, you need to use the Github api.
Using Github Api via the Octokit library (you can directly make the Github REST calls or use another lib.), you can request all the open pull requests fairly easily:
public static async Task getPullRequests ()
{
var client = new GitHubClient (new ProductHeaderValue ("PlayScript"));
// Login Credentials if you need them for an enterprise acct/repo
// client.Credentials = GithubHelper.Credentials;
var connection = new Connection (new ProductHeaderValue ("PlayScript"));
var api = new ApiConnection (connection);
var pullrequests = new PullRequestsClient (api);
pulls = await pullrequests.GetAllForRepository ("PlayScriptRedux", "playscript");
}
....
Task.WaitAll(getPullRequests());
foreach (var pullrequest in pulls) {
Console.WriteLine (pullrequest.IssueUrl);
}
That would list one open pull request for my playscript repo under the PlayScriptRedux organization, i.e. console output:
https://api.github.com/repos/PlayScriptRedux/playscript/issues/89
Look at the Octokit pull request test fixture for more info
Also review the Github pull requests api info

Related

Hugo Github Pages Error

I'm in the midst of starting a basic blog. I decided to try implementing github pages for the back end of my site using this particular theme (https://github.com/vickylai/hugo-theme-introduction).
I am able to successfully run both my site and my theme locally. However if I go to my pages link (https://ericksnetwork.github.io/) I get this 404 error:
File not found
The site configured at this address does not contain the requested file.
If this is your site, make sure that the filename case matches the URL.
For root URLs (like http://example.com/) you must provide an index.html file.
Read the full documentation for more information about using GitHub Pages.
I followed everything on the Hugo guidelines along with the guidelines on the actual github theme readme. Any advice would be appreciated.
This is the folder structure of what currently works locally:
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\.gitignore
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\.travis.yml
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\archetypes
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\archetypes\blog.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\archetypes\default.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\archetypes\projects.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\CHANGELOG.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\config.toml
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\about.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\blog
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\blog\coffee-ipsum.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\blog\hipster-ipsum.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\blog\startup-ipsum.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\contact.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\projects
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\projects\Design.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\projects\Photography.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\content\projects\Writing.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img\camera.jpg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img\fav.ico
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img\plant.jpg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img\profile.jpg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\exampleSite\static\img\workday.jpg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\images
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\images\screenshot.png
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\images\tn.png
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\_default
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\_default\list.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\_default\single.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\_default\taxonomy.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\_default\terms.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\404.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\blog
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\blog\list.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\blog\single.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\index.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\blogsection.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\footer.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\header.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\li.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\nav-list.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\nav-single.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\projects.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\partials\social.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\projects
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\layouts\projects\list.html
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\LICENSE
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\README.md
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\sass
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\sass\dark-style.sass
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\sass\light-style.sass
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\css
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\css\dark-style.css
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\css\font-awesome.min.css
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\css\light-style.css
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\css\nunito_sans.css
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\fontawesome-webfont.eot
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\fontawesome-webfont.svg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\fontawesome-webfont.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\fontawesome-webfont.woff
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\fontawesome-webfont.woff2
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\FontAwesome.otf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-Black.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-BlackItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-Bold.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-BoldItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-ExtraBold.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-ExtraBoldItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-ExtraLight.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-ExtraLightItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-Italic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-Light.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-LightItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-Regular.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-SemiBold.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\NunitoSans-SemiBoldItalic.ttf
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\fonts\OFL.txt
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\img
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\img\favicon.ico
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\img\workday.jpg
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\js
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\js\jquery-3.3.1.min.js
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\js\moment-timezone-with-data-2012-2022.js
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\js\moment-timezone.js
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\static\js\moment.js
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\textfile.txt
C:\Users\erick\Documents\Projects\ericksnetwork.github.io\themes\introduction\theme.toml
In case anyone stumbles across this in the future - I was simply missing the "hugo" command which publishes your site into a Public folder. This you then drop into your 'pages' repository.
I just hit your github link http://USERNAME.github.io and it is working fine now for you.
Enjoy !!! github services.
In case you have cloned from
https://github.com/vickylai/hugo-theme-introduction
then you first need to set-url for your own account.
Cross check :
Step 1. in gitbash type the command : git remote -v and look for the address where the changes will be pushed from git.
Step 2: Set the new url to your repository address :
git remote set-url origin https://github.com/YourUserName/NameofYourRepo
Step 3: remote -v . Now the adress to push your changes will have changed and you can push easily by .
Step 4 : git push origin master
Hope that resolves your issue.

Jenkins - tagging a build fails with NoHeadException

When I try to tag a specific build through Jenkins, I get the following error:
ERROR: Error tagging repo 'refs/remotes/origin/master' :
org.eclipse.jgit.api.errors.NoHeadException: Tag on repository without
HEAD currently not supported hudson.plugins.git.GitException:
org.eclipse.jgit.api.errors.NoHeadException: Tag on repository without
HEAD currently not supported at
org.jenkinsci.plugins.gitclient.JGitAPIImpl.tag(JGitAPIImpl.java:509)
at
hudson.plugins.git.GitTagAction$TagWorkerThread.perform(GitTagAction.java:199)
at hudson.model.TaskThread.run(TaskThread.java:129) Caused by:
org.eclipse.jgit.api.errors.NoHeadException: Tag on repository without
HEAD currently not supported at
org.eclipse.jgit.api.TagCommand.call(TagCommand.java:137) at
org.jenkinsci.plugins.gitclient.JGitAPIImpl.tag(JGitAPIImpl.java:507)
... 2 more Trying next branch Completed
When trying to tag in the workspace it works fine, HEAD is in fact attached, git refs look fine, could this be an issue that when Jenkins is trying to tag it is looking in the wrong working directory?
Is there a way to pull more verbose logs with how it's trying to tag?
FYI - using the Jenkins 2.81, and swarm Linux agents, latest Git plugin.
Consider the actual code throwing the exception:
try (RevWalk revWalk = new RevWalk(repo)) {
// if no id is set, we should attempt to use HEAD
if (id == null) {
ObjectId objectId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
if (objectId == null)
throw new NoHeadException(
JGitText.get().tagOnRepoWithoutHEADCurrentlyNotSupported);
Double-check your configuration: see "Jenkins Git plugin detached HEAD". You need to make sure Jenkins actually does checkout a branch.
Try for instance to add a simple test step with a git status in it, to validate that.

EGit: cannot push, cannot pull

I'am using EGit and I commited a change to my local git repository.
I'd like to push this change to a remote.
When doing that, a dialog screen pops up which shows "rejected-master-master-non-fast-forward". The answer of this linked question states that I have to pull first.
When doing the pull, an EGit exception is thrown:
org.eclipse.jgit.api.errors.TransportException: Nothing to fetch.
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:139)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:253)
at org.eclipse.egit.core.op.PullOperation$1.run(PullOperation.java:97)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.egit.core.op.PullOperation.execute(PullOperation.java:128)
at org.eclipse.egit.ui.internal.pull.PullOperationUI.execute(PullOperationUI.java:139)
at org.eclipse.egit.ui.internal.pull.PullOperationUI$1.runInWorkspace(PullOperationUI.java:114)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.eclipse.jgit.errors.TransportException: Nothing to fetch.
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1087)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
... 8 more
It seems that I'm stuck. Who can help me out?
UPDATE
The .git/config file in my repository contains (remote URL hid):
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
url = <URL_HIDDEN>
I'm using Eclipse Git Team Provider 3.4.1.201406201815
The configuration of the repository seems to miss this line in the [remote "origin"] section:
fetch = +refs/heads/*:refs/remotes/origin/*
It tells git to fetch all refs starting with refs/heads/ (all branches) and store them under refs/remotes/origin/ locally. E.g. the refs/heads/master in the remote repository will become refs/remotes/origin/master locally (or origin/master in short).
Can you add that and try if it makes pull work?
Also, it would be very interesting to know in which way you first created/cloned this repository.
I also faced the same problem when using egit and could not pull the changes. But previous answer helped a lot. Now, there can be two ways to update the config file.
Direct Update in the file : Goto local_repo_location/.git/ and open config file and add :
[remote "origin"]
url = YOUR_REPO_URL
push = ALREADY_FILLED_VALUE
fetch = +refs/heads/:refs/remotes/origin/
Updating config using eclipse : Goto Windows -> Preferences -> Team -> Git -> Configuration and now under Repository Settings tab look under -> remote -> origin.
Problem is there is no key for fetch.
Now click : Add Entry and provide the values as follows :
Key : remote.origin.fetch
Value : +refs/heads/:refs/remotes/origin/
Now we are done.
i had the same problem pulling from remote repo was giving error (org.eclipse.jgit.api.errors.transportexception)
here's what i did
changed the origin to my fork account and pulled.
changed the origin back to the actual value and pulled.
donot really know about the problem of egit but this two simple steps solved my problem, hope it helps

How to tell gruntfile to just test phantomJS on a pull request

I have been having pull request failing on Travis/SauceLabs while the merge build works good. When I get a pull request Travis fails with this code:
ERROR [launcher.sauce]: Can not start chrome (linux)
Failed to start Sauce Connect:
Could not start Sauce Connect. Exit code 1 signal: null
How can I test incoming pull requests just on Travis and test a merge on SauceLabs?
It's not possible yet to run pull requests on Sauce Labs when the sauce key/pass are encrypted. This is for safety reasons to not expose the credentials in case the PR has malicious code.
So what is possible is to use the
process.env.TRAVIS_PULL_REQUEST // (string)
to distinguish a pull request from a push/merge triggered test.
So, since this enviroment variable gives you a string with the pull request number or with "false", its possible to use it as a flag. So I used this on my Gruntfile:
var pullRequest = process.env.TRAVIS_PULL_REQUEST;
tasks = pullRequest != 'false' ? 'karma:continuous' : 'karma:sauceTask';
grunt.registerTask('default:travis', tasks);
and in my :continuous task I have only PhantomJS
continuous: {
browsers: ['PhantomJS']
},

How to set the upstream branch for new local branch with JGit

I use the following code to create a new branch from origin/master:
CreateBranchCommand branchCmd = git.branchCreate();
branchCmd.setForce(true);
branchCmd.setName("newFeatureBranch");
branchCmd.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
branchCmd.setStartPoint("origin/master");
branchCmd.call();
After running this code I get a new local branch with the following upstream:
But that is not what I want. Its upstream should be set to refs/heads/newFeatureBranch:
How do I set the upstream in the new branch?