Getting all files for repository using OctoKit - c#

I want to get all informations about files from my github repository using octokit
projectis: http://octokitnet.readthedocs.org/en/latest/contributing/
Updated:
what I thought I can do is
getAllFilesFromRepository
that will return json with something like example below for all files in repository
{
"type": "symlink",
"target": "/path/to/symlink/target",
"size": 23,
"name": "some-symlink",
"path": "bin/some-symlink",
"sha": "452a98979c88e093d682cab404a3ec82babebb48",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/bin/some-symlink",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
"html": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink"
}
}
Please note
I do not want to download any files at all or write query with multiple calls to retrieve the data.

I'm not sure I understand the question, but please read the Getting Started guide first around the setup you need.
This is an example of how to download the contents of a given repository:
var github = new GitHubClient(...); // TODO: other setup
var contents = await github
.Repository
.Content
.GetAllContents("octokit", "octokit.net");
...
var docs = await github
.Repository
.Content
.GetAllContents("octokit", "octokit.net", "docs");
Change the values to suit the repository you're interested in. If you want to download a non-default branch, use GetAllContentsByRef instead.

GetAllContents method would work fine but one small issue is that it would not iterate recursively through all the sub-folders in your repository. It gives only the files and folders present in the top-level. If you want to list out all the files of your repository, I would suggest you to use the GetRecursive method as follows:
var trees = _gitHubClient.Git.Tree.GetRecursive(_config.Owner, _config.RepositoryId, <<APPROPRIATE SHA>>).Result;
You can get the SHA for the latest commit or as per your requirement.This method would give you a tree response which has sufficient details such as the SHA, Path, Type and Size.

Related

How do you create a global configuration for Playwright .NET?

I am planning to use Playwright .NET to perform automated UI testing in a C# dotnet project. The issue is that I would like to have global configuration that can be set rather than needing to define the same settings repeatedly in the context of each test, but I cannot seem to find any working examples.
The documentation at playwright.dev implies that I should be able to simply include a "playwright.config.js" file at the root of the project, but no clear definition of what the content of that file should be. I have experimented with the example provided for Playwright Node.js, using:
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
use: {
// Browser options
headless: false,
slowMo: 50,
// Context options
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
// Artifacts
screenshot: 'only-on-failure',
//video: 'retry-with-video',
},
outputDir: "C:\\stuff\\screenshots",
preserverOutput: 'always',
quiet: false,
};
export default config;
However, these settings do not seem to be applied and there is no indication that the playwright.config.js file is either loading or failing.
Any help or a simple example to get me pointed in the right direction would be much appreciated.
LaunchAsync expects a BrowserTypeLaunchOptions class. You could have that object serialized in a JSON file, parse it and pass that options instance as an argument.

Why can't I create a valid style via the mapbox api using the examples they provide?

I amp attempting to create a new mapbox style via the mapbox api. When the create process completes, I am getting a success confirmation back, but I cannot use or view the style after it is created. Based on these docs and these docs, I am sending a payload to this api endpoint:
https://api.mapbox.com/styles/v1/[accountname]
The payload I am sending is this:
{
"version": 8,
"name": "mystyle via api",
"sprite": "mapbox://sprites/mapbox/bright-v8",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"glyphs": null,
"layers": []
}
After sending this payload to the mapbox api, I receive this message back:
{
"version": 8,
"name": "mystyle via api",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"sprite": "mapbox://sprites/[accountname]/ckby5s52p2r9v1hmwgkrzenvw/3teom2ial2ryn2u97lclizpce",
"glyphs": "mapbox://fonts/[accountname]/{fontstack}/{range}.pbf",
"layers": [],
"created": "2020-06-27T21:30:49.047Z",
"id": "ckby5s52p2r9v1hmwgkrzenvw",
"modified": "2020-06-27T21:30:49.047Z",
"owner": "[accountname]",
"visibility": "private"
}
Then I proceed to my account in the portal and I see my new style:
However, something is wrong. The preview icon shows just a transparent graphic. And when I click on the style to view/edit it, I get this cryptic error message "Cannot read property 'mapbox:decompiler' of null":
What am I missing here? I am finding the documentation for this process very spread out through several documents. But I am copying the examples in the snippets verbatim
This is a "valid" style, but it has no layers (see the last field of the JSON), that's why it doesn't display anything. (I know this is verbatim from the example in the Create a style docs)
The key concept here to master is the difference between Sources and Layers. Sources are "data sources": you won't see them unless you have a Layer displaying it. Some types of Sources can contain many layers (see the source-layer property in the Layer object), and/or you might want to display the same source with different stylings across different maps. That's one reason they are separated.
Or, as the Sources docs put it:
Adding a source isn't enough to make data appear on the map because sources don't contain styling details like color or width. Layers refer to a source and give it a visual representation. This makes it possible to style the same source in different ways, like differentiating between types of roads in a highways layer.
Combining the Style object sample with the Layer object sample would give you something like this:
{
"version": 8,
"name": "mystyle via api",
"sprite": "mapbox://sprites/mapbox/bright-v8",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"glyphs": null,
"layers": [
{
"id": "water",
"source": "mapbox-streets",
"source-layer": "water",
"type": "fill",
"paint": {
"fill-color": "#00ffff"
}
}
]
}
Now, keep in mind that the global Mapbox styles contain several layers (maybe up to a couple dozen), with very fine settings such as what type of features should show at which zoom level and with what configurations, etc. Most applications should not need to recreate those from scratch.
If you want to overlay dynamic data (to be decided at runtime), you can use one of the global styles and dynamically add a Layer on top of an untouched default style. The link is for Mapbox GL JS, assuming the UI is browser-based. If the UI is a mobile app, there are corresponding methods in the iOS and Android SDKs.
Now, if you don't need dynamic data at all, consider Mapbox Studio instead. This will allow you to create a custom style (with the default styles as templates if you want) and add/remove layers. For example, if mapbox://styles/mapbox/streets-v11 is almost a perfect fit, but you don't need to (say) show small town names, you can create a custom template in Mapbox Studio and remove just that. In the end, it will you give you a style ID which you can just put into your map like a default (global) style.
Also note that, depending on your case, you may combine both approaches.

TFS Capacity plan reading from c#

Am doing a reporting tool out of tfs. i was able to read the work item and iteration related information from tfs. How to get the iteration capacity plan information from tfs. using WIQL or any other option. i need to get the information in my c# code.
Thanks in advance for all the help.
It's not able to do this through Client Object Model. Please refer this similar question: TFS 11 2012 API Questions : query capacity and days off
These values are only available from the Server Object Model (there is no Client Object Model equivalent at the moment). The interfaces and objects are all made Internal so even on the server you can't access these values.
internal TeamCapacity GetTeamIterationCapacity(Guid teamId, Guid iterationId);
Declaring Type: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common.DataAccess.TeamConfigurationComponent
Assembly: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common, Version=12.0.0.0
You could either directly query from the ProjectCollection database from the tables mentioned by James Tupper in this thread.
Or you could also use Rest API to Get a team's capacity or Get a team member's capacity will get a response as below:
{
"values": [
{
"teamMember": {
"id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"displayName": "Chuck Reinhart",
"uniqueName": "fabrikamfiber3#hotmail.com",
"url": "https://fabrikam-fiber-inc.vssps.visualstudio.com/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"imageUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
},
"activities": [
{
"capacityPerDay": 0,
"name": null
}
],
"daysOff": [],
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6d823a47-2d51-4f31-acff-74927f88ee1e/748b18b6-4b3c-425a-bcae-ff9b3e703012/_apis/work/teamsettings/iterations/2ec76bfe-ba74-4060-970d-4567a3e997ee/capacities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
}
]
}
Iteration objects are part of Project settings, you might need to query the iteration details from there and not from work item.

Mapping static file directories in ServiceStack

I'm building a self-host application in C# using Service Stack. I'd like the application to share content based on some configuration data.
During AppHost.Configure I'd like to read-in a configuration file and recursively share several directories. The directories may be local or shared folders depending on each element in the configuration.
For example, if my config looks like this:
[
{
"sourceId": "TEST1",
"contentPath": "\\\\nas01\\files"
},
{
"sourceId": "TEST2",
"contentPath": "d:\\files"
}
]
I'd like the directories to be recursively accessible like this:
http://localhost/TEST1/....
http://localhost/TEST2/....
Reading the config file is no problem, really, I just want to know the right way to map these directories so I can use the built-in static handling capabilities of ServiceStack.
So I guess my question is:
What's the right way, in Service Stack, to map a static content directory at run-time?
Many thanks!
-Z
New support for FileSystem Mapping was added in this commit which will now let you register file system mappings by overriding GetVirtualFileSources() in your AppHost, e.g:
public override List<IVirtualPathProvider> GetVirtualFileSources()
{
var existingProviders = base.GetVirtualFileSources();
existingProviders.Add(new FileSystemMapping(this, "TEST1", "\\\\nas01\\files"));
existingProviders.Add(new FileSystemMapping(this, "TEST2", "d:\\files"));
return existingProviders;
}
This change is available from v4.5.5+ that's now available on MyGet.

Create Build Definition from Template with TFS 2015 .NET Client Libraries

I'm using the .NET Client Libraries for VSTS/TFS 2015 to programmatically create a build definition based off of a template that I've grabbed in another team project.
I can get a build definition template (2.0) by using:
BuildDefinitionTemplate builddeftemplate = buildHttpClient.GetTemplateAsync(teamProject, templateId).Result;
And I can create a build definition by using:
BuildDefinition builddef = new BuildDefinition();
builddef.Project = newTeamProject;
But there doesn't look like a way to pass in a template as a property of the build definition, nor create a build definition from the template.
When looking at the documentation for the REST API, the GET request actually looks like it returns a lot of JSON:
{
"id": "vsBuild",
"name": "Visual Studio",
"canDelete": false,
"category": "Build",
"iconTaskId": "71a9a2d3-a98a-4caa-96ab-affca411ecda",
"description": "Build and run tests using Visual Studio. This template requires that Visual Studio be installed on the build agent.",
"template": {
"build": [
{
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"task": {
"id": "71a9a2d3-a98a-4caa-96ab-affca411ecda",
"versionSpec": "*"
},
"inputs": {
"solution": "**\\*.sln",
"msbuildLocation": "",
"vsLocation": "",
"msbuildArgs": "",
"platform": "$(BuildPlatform)",
"configuration": "$(BuildConfiguration)",
"clean": "false"
}
},
...
So I think that it might be possible to only grab parts of the returned template as a JSON object and pass through a POST of the build definition with those parts, but it seems like that would have to solely be the REST API route.
Is this possible with the .NET Client Libraries? Or is there an easier way that I might have missed?
There isn't a way to pass in a template as a property of the build definition. However, there's another way to achieve it. You can clone/import/export build definition between team projects through .net libraries.
var cred = new VssCredentials(new WindowsCredential(new NetworkCredential(username, password)));
var buildClient = new BuildHttpClient(new Uri(collectionURL, UriKind.Absolute), cred);
 
var buildDef = (await buildClient.GetDefinitionAsync(sourceProj, buildDefId)) as BuildDefinition;
 
buildDef.Project = null;
buildDef.Name += "_clone";
 
await buildClient.CreateDefinitionAsync(buildDef, targetProj);
From above code you can authenticate to the team server and retreive the build definition object from the source project by the providing project name and the build definition id.
And then you need to remove the reference to the project. Since build definition contains a reference to the project it would not be possible to import it into a different project. Finally create a new build definition in target project providing the definition objecte retreived from previous project.
Next step is to export the build definition to a file so we can latter import it. By using a json serializer to serialize the build definition and save it to a file.
var buildDef = (await buildClient.GetDefinitionAsync(project, buildDefId)) as BuildDefinition;
buildDef.Project = null;
File.WriteAllText(filePath, JsonConvert.SerializeObject(buildDef));
Finally add a import method, more details please refer this link
if (!File.Exists(filePath))
throw new FileNotFoundException("File does not exist!", filePath);
Console.WriteLine($"Importing build definition from file '{filePath}' to '{project}' project.");
var buildDef = JsonConvert.DeserializeObject<BuildDefinition>(File.ReadAllText(filePath));
buildDef.Name = newBuildName;
await buildClient.CreateDefinitionAsync(buildDef, project);

Categories