How to send push options with LibGit2Sharp? - libgit2sharp

How to use LibGit2Sharp to send parameters to server similar to the command git --push-option?

See PushOptions
PushOptions options = new PushOptions()
{
CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler((url, usernameFromUrl, types) => credentials),
};
repo.Network.Push(CurrentBranch, options);
Thanks,
Garrick

Related

Complete TFS Pull Request programmatically

Using the Microsoft.TeamFoundationServer.Client (15.112.1) to connect to a TFS 2017 Update 2 server we can get details about an existing PR like this:
var connection = new VssConnection(collectionUri, credentials);
var client = connection.GetClient<GitHttpClient>();
var pr = await client.GetPullRequestByIdAsync(pullRequestId);
Also, we can create new PR like this:
var pr = await client.CreatePullRequestAsync(
new GitPullRequest
{
SourceRefName = "master",
TargetRefName = "develop",
Title = "[Automatic Merge]"
},
projectName, repositoryName);
In addition, we can vote on the PR like this:
var pr = await client.CreatePullRequestReviewerAsync(
reviewer, projectName, repositoryName, pullRequestId, authorizedIdenity.Id.ToString());
Is there any way to complete the PR (overriding or not existing branch
policies) and proceed with the merge operation?
The GitHttpClient has an UpdatePullRequestAsync method.
To complete the pull request you need to update the Status property of your pull request. and use the UpdatePullRequestAsync method to complete your PR.
Please make sure that to set the the CompletionOptions property to specify whether you are merging the commit, delete the source branch etc.
So your code would look like following
pr.Status = PullRequestStatus.Completed
pr.CompletionOption = new GitPullRequestCompletionOption() { SquashMerge = true };
client.UpdatePullRequest(pr, repositoryId, pullRequestId);
EDIT:
The ByPassPolicy is not available for the released version of Microsoft.TeamFoundationServer.ExtendedClient yet.
However, if you install the pre-release NuGet Package v15.122.1-preview of library Microsoft.TeamFoundationServer.ExtendedClient, you will see the option ByPassPolicy as a property in the GitPullrequestCompletionOptions class. You can set it to true to by pass policy.

Why does vsts-node-api always return Invalid Resource - 401?

I am attempting to use the vsts-node-api package in a custom Build task that I am writing and trying to use on on-prem tfs2017. I have leveraged some of the Sample code found on the github repo, and I've found that it returns an error of Invalid Resource. Doing some debugging in VSCode and then adding some debug logging to the rest code, I find that the rest call returns a 401. The error occurs after I get the WebApi and then try to connect.
I've attempted to use the PAT Handler, and the NtlmHandler, but no luck. If I hit the URI through my browser, I successfully get the JSON returned.. any help would be super appreciated.
export async function getWebApi(pwd:string): Promise<vm.WebApi> {
return new Promise<vm.WebApi>(async (resolve, reject) => {
try {
console.log("in the common getter");
let serverUrl = 'https://mylocalserver/tfs/mycollection';
let token = ' my PAT on the server, that has full access ';
let authHandler = vm.getPersonalAccessTokenHandler(token);
let option = {
ignoreSslError: true
};
let vsts: vm.WebApi = new vm.WebApi(serverUrl, authHandler,options);
console.log("got web api?");
let connData: lim.ConnectionData = await vsts.connect();
console.log('Hello ' + connData.authenticatedUser.providerDisplayName);
resolve(vsts);
}
catch (err) {
console.log("error in get api " + err.message);
reject(err);
}
});
thanks
It looks like this response from the VSTFS team is the way to go.
TLDR;
Generate a bearer OAuth token per build to talk back to VSTS.

Using Twilio API in Phalcon3

I want to integrate Twilio SMS Api in Phalcon 3 using dependency injection.It would be great if anyone could guide me in this process.
Just like any other PHP library that you want to use, you first need to check what is the installation method.
As noted by Nikolay Mihaylov in the comments, check the documentation for Twillo here:
https://www.twilio.com/docs/libraries/php
As you will see they do offer an installation through composer. All you need to do in your project then is:
composer require twilio/sdk
Registering Twillo in your DI container is the same as any other service:
// Your Account SID and Auth Token from twilio.com/console
$config = [
'sid' => 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'token' => 'your_auth_token',
]
// $di is the DI container
// Using the $config variable in the current scope
$di->set(
'db',
function () use ($config) {
$sid = $config['sid'];
$token = $config['token'];
$client = new \Twilio\Rest\Client($sid, $token);
return $client;
}
);
References:
https://docs.phalconphp.com/en/latest/reference/di.html
https://www.twilio.com/docs/libraries/php

Twilio REST API How to get Sid

I am still new to Twilio. I am writing a PHP script which will connect to Twilio and parse some information about calls. I am using the code from this page:
https://www.twilio.com/docs/api/rest/call
Here is my code:
require_once '../twilio-library/Services/Twilio.php';
// Twilio REST API version
$version = '2010-04-01';
// Set our AccountSid and AuthToken
$sid = 'abc132xxxxx';
$token = 'xxxxeeffv';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls as $call) {
echo "->".$call->Sid."<- <br/>";
}
The browser just outputs many blanks. No Sid values. What am I doing wrong?
Twilio Developer Evangelist here.
Try doing the following to get call information.
<?php
require_once '../twilio-library/Services/Twilio.php';
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'abc132xxxxx';
$token = 'xxxxeeffv';
$client = new Services_Twilio($sid, $token);
// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls as $call) {
echo $call->sid;
}
Notice that if you're using the latest version of the library, you don't need to specify a version on your request. Double check that the path ../twilio-library/Services/Twilio.php is correct for you though.
If you're only testing, you could move the file Twilio.php to the same directory where your code is and just import Twilio.php on it.
If you then decide to filter the logs by date, here's how you would do it.
// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls->getIterator(0, 50, array(
"Status" => "completed",
"StartTime>" => "2015-03-01",
"StartTime<" => "2015-05-10"
)) as $call
) {
echo $call->sid;
}
Let me know how it goes.

LibGit2Sharp fetching error "Too many redirects or authentication replays"

I receive the error “Too many redirects or authentication replays” when trying to fetch with libgit2sharp from a TFS server.
I've tried the solutions in the article below and none seem to be working.
LibGit2Sharp: Fetching fails with "Too many redirects or authentication replays"
code using DefaultCredentials():
CredentialsHandler credHandler = (_url, _user, _cred) => new DefaultCredentials();
var fetchOpts = new FetchOptions { CredentialsProvider = credHandler };
using (var repo = GetRepository())
{
Remote remote = repo.Network.Remotes["origin"];
repo.Network.Fetch(remote, fetchOpts);
} // using

Resources