How to set a remote using libgit2sharp? - push

I'm trying to do something like this:
var origin = repository.Network.Remotes["origin"];
repository.Head.Remote = origin;
The only problem is that "Remote" is readonly (I'm using 0.14.1.0). How do i set a default remote for HEAD?

Although I'd greatly recommend to update your version, the code below should get your started and work in v0.14.1.
Remote remote = repo.Network.Remotes["origin"];
Branch branch = repo.Head;
Branch updatedBranch = repo.Branches.Update(branch,
b => b.Remote = remote.Name,
b => b.UpstreamBranch = branch.CanonicalName);
See also this SO answer which provides some explanation about the branch tracking configuration.

Related

How to get contents of file in pull request from pygithub?

I'm not able to find how to get contents of file present in pull request on github. Is there any way to do this using pygithub?
For repository, we can do this using
contents = repo.get_contents(filename)
However, I did not find such api for pull request object. Is there any way to do this?
I have found a nice workaround to this. We can not get contents from File objects, however, it is possible to get them from repository, at any version. I did this like following :
This works irrespective of PR is open/closed/merged.
(1) Grab commits from PR.
(2) Grab files from commits.
(3) Use Repository object to get the contents of file at reference corresponding the sha of commit in PR.
Example :
github = Github(login_or_token=my_github_token)
repo = github.get_repo(repo_name, lazy=False)
# Grab PR
pull_number = 20
pr = repo.get_pull(pull_number)
commits = pr.get_commits()
for commit in commits:
files = commit.files
for file in files:
filename = file.filename
contents = repo.get_contents(filename, ref=commit.sha).decoded_content
# Now do whatever you want to do with contents :)
Take a look at this: https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files
Have not tried, but pygithub does have a method for this called get_files to use this API call: https://pygithub.readthedocs.io/en/latest/github_objects/PullRequest.html#github.PullRequest.PullRequest.get_files
EDIT: Using requests:
import requests
username = 'astrochun'
repo = 'Zcalbase_gal'
pr = 84
response = requests.get(f"https://api.github.com/repos/{username}/{repo}/pulls/{pr}/files")
dict0 = response.json()
pr_files = [elem['filename'] for elem in dict0]

Can't set confirmationHandler on a connection with confirmation-window-size < 0 error when deployBridge with DEFAULT_CONFIRMATION_WINDOW_SIZE(-1)

I try to deploy Core Bridge via ActiveMQServer.deployBridge(BridgeConfiguration config), I create BridgeConfiguration with default value (DEFAULT_CONFIRMATION_WINDOW_SIZE = -1) for confirmationWindowSize
and put it in ActiveMQServer.deployBridge(BridgeConfiguration config), but after that, I get the errors
You can't set confirmationHandler on a connection with
confirmation-window-size < 0. Look at the documentation for more
information.
What am I doing wrong or is it a bug?
Artemis version 2.16.0
This looks like a minor bug with the default value for org.apache.activemq.artemis.core.config.BridgeConfiguration#confirmationWindowSize. Currently it is using this:
private int confirmationWindowSize = ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE;
However, it should be using this:
private int confirmationWindowSize = ActiveMQDefaultConfiguration.getDefaultBridgeConfirmationWindowSize();
You can work around this issue by setting the confirmation window size manually, e.g.:
BridgeConfiguration myBridgeConfiguration = new BridgeConfiguration();
myBridgeConfiguration.setConfirmationWindowSize(ActiveMQDefaultConfiguration.getDefaultBridgeConfirmationWindowSize());
I opened a Jira issue for this, sent a PR, and the PR has been merged. The fix will appear in ActiveMQ Artemis 2.17.0.

ejabberd - Get publisher JID in pubsub item

http://www.xmpp.org/extensions/xep-0060.html#impl-association defines an attribute called 'itemreply' that lets you add the publisher information along with the item being published. It doesn't look like ejabberd has implemented the above option. Is there any other workaround for this ?
According to https://support.process-one.net/browse/EJAB-1347 there is an patch available that can accomplish it but i am not sure on how to apply the patch. Looking for guidance on the same.
Thanks,
Mithun
The patch is too old to apply as is on ejabberd code base. It would need to be updated to latest version, but I do not think it is a highly requested feature.
You should probably submit a feature request on project Github: https://github.com/processone/ejabberd/issues
Managed to change the code to add publisher information. Here are the steps needed to to the same.
1) open the file src/mod_pubsub.erl
2) Find the following function
itemAttr(ItemId) -> [{<<"id">>, ItemId}].
3) Add a new function below the above mentioned function
itemAttr(ItemId, From) -> [{<<"id">>, ItemId},{<<"publisher">>, From}].
4) Next find the function named
broadcast_publish_item(Host, Node, Nidx, Type, NodeOptions, ItemId, From, Payload, Removed) ->
5) Replace
Stanza = event_stanza(
[#xmlel{name = <<"items">>, attrs = nodeAttr(Node),
children = [#xmlel{name = <<"item">>, attrs = itemAttr(ItemId),
children = Content}]}]),
with
Stanza = event_stanza(
[#xmlel{name = <<"items">>, attrs = nodeAttr(Node),
children = [#xmlel{name = <<"item">>, attrs = itemAttr(ItemId, jlib:jid_to_string(From)),
children = Content}]}]),
6) Recompile the code using
sudo make; sudo make install;
Restart your server and you should get the publisher information along with the item being published.

how to get a list of commits from refChanges in Atlassian Stash Pre Receive Repository Hook

Im trying to write a stash plugin that will iterate through the commits in a change set pushed to stash in a Pre Receive Repository Hook.
The API passes a Collection of refChange in the onReceive method.
public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)
if I make 3 commits then push I get one RefChange which looks like this
refId = refs/heads/master
fromHash = ded3e4583653f14892cc3e8a898ba74ee75e1a58 // First Commit in change set
toHash = ae017dcdadf7ca69617fb05f6905cccfe2aa4229 // Most recent commit
type = "UPDATE"
Id like to get a collection of all the commits so that I can get all the commit messages.
I'm looking at com.atlassian.stash.commit.CommitService getCommit and getCommits. I think I need to getCommitsBetween but can't quite figure out how to crate the GetCommitsBetween parameter needed from the RefChange I have.
Am I even heading down the right path here?
Even though the CommitsBetweenRequest page on the Atlassian Stash API documentation is one of the few pages with an explanation, it took some trial and error to figure this out. GetCommitsBetween works but here's the trick...
Set the commitsBetweenBuilder.exclude to the starting commit in the change set and commitsBetweenBuilder.include to the ending commit hash.
CommitsBetweenRequest.Builder commitsBetweenBuilder = new CommitsBetweenRequest.Builder(context.getRepository() );
commitsBetweenBuilder.exclude(refChange.getFromHash()); //Starting with
commitsBetweenBuilder.include(refChange.getToHash()); // ending with
PageRequest pageRequest = new PageRequestImpl(0,6);
Page<Commit> commits = commitService.getCommitsBetween(commitsBetweenBuilder.build(), pageRequest);
//TODO: handle Pages
for (Commit commit : commits.getValues()) {
hookResponse.out().println("Message = " + commit.getMessage() + "\n");
}
I wasn't able to get the dependency injection working for the CommitService. Spring for some reason wasn't able to find it, when trying to run in locally ???
I did getting it working using the component locator.
CommitService commitService = ComponentLocator.getComponent(CommitService.class);

How can I Diff a Svn Repository using SharpSvn

My question is quite simple and with the SharpSvn Api, it should be easy as well. Here what I did:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetChanged(o, out changeList); // <-- Exception
}
and when I call the GetChanged, I get an exception:
Can't open file 'c:\project\format': The system cannot find the file specified.
So, Maybe there is something I'm missing? Or maybe it's not the right way to do find out the list of files and folders that were modified in the local repository?
Thanks in advance.
The SvnLookClient class in SharpSvn is the equivalent to the 'svnlook' console application. It is a low level tool that enables repository hooks to look into specific transactions of a repository using direct file access.
You probably want to use the SvnClient class to look at a WorkingCopy and most likely its Status() or in some cases simpler GetStatus() function to see what changed.
The path that the SvnLookOrigin constructor wants is actually:
path = "c:\project\.svn\";
That is, it wants that special ".svn" directory not just the root of where the source is checked out to.
Although you probably do want to listen to Bert and do something like:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetStatus(o, out changeList); // Should now return the differences between this working copy and the remote status.
}