Github API: How to sort public repositories by count of stars? - github-api

I am looking for api on github that could give me a count of stars for repositories
I know about /repositories which give me public repositories but I don't know how to get count of stars of repository.
Could anybody help?

From /repositories get all the public repositories. In response you would get name of the owner and also repository name, then use Get on each of those repositories. In the response of for each of those repositories, field stargazers_count will give you number of stars each repository has.
Some sample python code:
import requests
public_repos = requests.get('https://api.github.com/repositories').json()
for repo in public_repos:
repo_name = repo['name']
owner = repo['owner']['login']
repo_info = requests.get('https://api.github.com/repos/'+owner+'/'+repo_name)
stars = repo_info.json()['stargazers_count']
print(repo_name, stars)
The output is:
grit 1874
merb-core 401
rubinius 2176
god 1592
jsawesome 12
Have a look at /repositories and Get

Related

flight offer search not pulling all air fares

I would like to seek help on the codes below.
Apparently, the code works by pulling out air fares but it seems like it does not pull out all the available air fares that I can see directly from the airlines websites.
Could anyone please assist me to let me know what's happening? Thanks!
from amadeus import Client, ResponseError
Origin = "SIN"
Destination = "CDG"
amadeus = Client(hostname='production', client_id='HIDDEN', client_secret='HIDDEN')
try:
'''
Find the cheapest flights from Origin to Destination
'''
response = amadeus.shopping.flight_offers_search.get(
#originLocationCode=Origin, destinationLocationCode=Destination, departureDate='2023-04-04', adults=1)
originLocationCode=Origin, destinationLocationCode=Destination, departureDate='2023-03-03', returnDate='2023-04-04', travelClass='BUSINESS', includedAirlineCodes='SQ', currencyCode='SGD', adults=1)
print(response.data)
except ResponseError as error:
raise error
The Self-Service APIs only return public fares coming from the GDS. That means that you will find discrepancy for both the flights and the prices too comparing to some websites you might visit.
For more details check the section carriers and rates in the developer guides.

Retrieving project coverage with python-gitlab

I use the python-gitlab module to retrieve the project statistics for a number of projects in Gitlab via its API. One of the values I want to get is the CI status and the code coverage. While the status is easy:
from gitlab import Gitlab
gl = Gitlab('http://gitlab.example.com')
project = gl.projects.get('olebole/myproject')
branch = project.branches.get(project.default_branch)
commit = project.commits.get((branch.commit['id'])
print(commit.last_pipeline['status'])
I didn't find a way to retrieve the coverage; also adding with_stats=True to the commit retrieval didn't make it.
How can one get this value?
This is in the pipeline object:
pipeline = project.pipelines.get(commit.last_pipeline['id'])
print(pipeline.status, pipeline.coverage)

Microsoft.TeamFoundation.Build.WebApi Get Build Status Launched by PR policy

In our pipeline we programmatically create a pull request (PR). The branch being merged into has a policy on it that launches a build. This build takes a variable amount of time. I need to query the build status until it is complete (or long timeout) so that I can complete the PR, and clean up the temp branch.
I am trying to figure out how to get the build that was kicked off by the PR so that I can inspect the status by using Microsoft.TeamFoundation.Build.WebApi, but all overloads of BuildHttpClientBase.GetBuildAsync require a build Id which I don't have. I would like to avoid using the Azure Build REST API. Does anyone know how I might get the Build kicked off by the PR without the build ID using BuildHttpClientBase?
Unfortunately the documentation doesn't offer a lot of detail about functionality.
Answering the question you asked:
Finding a call that provides the single deterministic build id for a pull request doesn't seem to be very readily available.
As mentioned, you can use BuldHttpClient.GetBuildsAsync() to filter builds based on branch, repository, requesting user and reason.
Adding the BuildReason.PullRequest value in the request is probably redundant according to the branch you will need to pass.
var pr = new GitPullRequest(); // the PR you've received after creation
var requestedFor = pr.CreatedBy.DisplayName;
var repo = pr.Repository.Id.ToString();
var branch = $"refs/pull/{pr.PullRequestId}/merge";
var reason = BuildReason.PullRequest;
var buildClient = c.GetClient<BuildHttpClient>();
var blds = await buildClient.GetBuildsAsync("myProject",
branchName: branch,
repositoryId: repo,
requestedFor: requestedFor,
reasonFilter: reason,
repositoryType: "TfsGit");
In your question you mentioned wanting the build (singular) for the pull request, which implies that you only have one build definition acting as the policy gate. This method can return multiple Builds based on the policy configurations on your target branch. However, if that were your setup, it would seem logical that your question would then be asking for all those related builds for which you would wait to complete the PR.
I was looking into Policy Evaluations to see if there was a more straight forward way to get the id of the build being run via policy, but I haven't been able to format the request properly as per:
Evaluations are retrieved using an artifact ID which uniquely identifies the pull request. To generate an artifact ID for a pull request, use this template:
vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}
Even using the value that is returned in the artifactId field on the PR using the GetById method results in a Doesn't exist or Don't have access response, so if someone else knows how to use this method and if it gives exact build ids being evaluated for the policy configurations, I'd be glad to hear it.
An alternative to get what you actually desire
It sounds like the only use you have for the branch policy is to run a "gate build" before completing the merge.
Why not create the PR with autocomplete.
Name - autoCompleteSetBy
Type - IdentityRef
Description - If set, auto-complete is enabled for this pull request and this is the identity that enabled it.
var me = new IdentityRef(); // you obviously need to populate this with real values
var prClient = connection.GetClient<GitHttpClient>();
await prClient.CreatePullRequestAsync(new GitPullRequest()
{
CreatedBy = me,
AutoCompleteSetBy = me,
Commits = new GitCommitRef[0],
SourceRefName = "feature/myFeature",
TargetRefName = "master",
Title = "Some good title for my PR"
},
"myBestRepository",
true);

Retrieve all repositories that contain a file in a path within a repository

I'm currently using Octokit.Net in attempt to search and find repositories that meet a specific criteria:
Repositories that include Android somewhere.
Includes any .xml files within a path matching res/layout
Has a minimum of 100 stars
etc
The goal is to find Android repositories over 100 stars that include any .xml files in the res/layout path.
To do this, I've tried to create two separate requests, one in which I use a SearchRepositoriesRequest to find repositories that match the Android characteristics and stars.
var request = new SearchRepositoriesRequest("android")
{
Stars = Range.GreaterThan(100),
In = new[] { InQualifier.Readme, InQualifier.Description, InQualifier.Name },
SortField = RepoSearchSort.Stars,
};
I then add these repositories to a RepositoryCollection and use it within the SearchCodeRequest which my hope is that within each of these repositories I can then search for the Extension, Language, Path, and more.
var request1 = new SearchCodeRequest()
{
Repos = repositoryCollection,
In = new[] { CodeInQualifier.File, CodeInQualifier.Path },
Language = Language.Xml,
Size = Range.GreaterThan(100),
Path = "res/layout",
Extension = "xml",
};
Generally speaking, is there a way to search a collection of repositories that includes a generic file in a path?
I'm more or less seeing the same results from the Advanced GitHub Search. Sadly this makes me think this isn't possible today with GitHub v3 API.
I did find some limitations within various blogs and similar that seem like this might not be possible?
Considerations for code search
Due to the complexity of searching code, there are a few restrictions on how searches are performed:
Only the default branch is considered. In most cases, this will be the master branch.
Only files smaller than 384 KB are searchable.
You must always include at least one search term when searching source code. For example, searching for language:go is not valid, while amazing language:go is.

How to run one feature file following with another feature file?

I have 2 feature files i.e userstoryteacher1.feature and userstoryteacher2.feature . Basicaly userstoryteacher1.feature have the steps where it has 2 tags #Dev and #QA.
I want to run the feature files in following way :-
If i pass the #Dev,#tagteacher in Cucumber class then it should pick the dev url to open the page with crentials.
If i pass the #QA,#tagteacher in Cucumber class then it should pick the qa url to open the page with credentials.
import org.junit.runner.RunWith;
import com.optum.synergy.common.ui.controller.WebController;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = { "json:target/test_results/cucumber.json"},
features = { "src/main/resources/ui/features" },
tags ={"#Dev,#tagteacher"},
snippets = SnippetType.CAMELCASE
)
public class CucumberRunnerTest {
public static void tearDown(){
WebController.closeDeviceDriver();
}
}
---------------------------------------------------------------------------
userstoryteacher1.feature file :-
#TestStory
Feature: Teachers timesheet need to be filled
I want to use this template for my feature file
Background:
Scenario Outline: Open Webpage
Given User Open teacher application with given <ENDPOINT>
And Login into application with given <USERNAME> and <PASSWORD>
And User clicks on teacher submission link
#DEV
Examples:
| endpoint | USERNAME | PASSWORD |
| http://teachersheetdev.ggn.com | sdrdev| aknewdev|
#QA
Examples:
| endpoint | USERNAME | PASSWORD |
| http://teachersheetqa.ggn.com | sdrqa | aknewdev|
-----------------------------------------------------------------------------
userstoryteacher2.feature file :-
Feature : I'm at the teachers page
#tagteacher
Scenario: Open app home page and click the button
Given I'm at the teachersheet homepage
When User clicks Add Task button
Then User should see the tasks schedule
Cucumber is designed so that you can't link scenarios or feature files together. Each scenario should be run as an independent 'test' that starts from the beginning.
Programming with feature files is a terrible anti-pattern. Instead push the programming down into the step definition layer, or better yet into helpers that the step definitions use.
If you want to get the best out of Cucumber you need to use it to only express WHAT is being done and WHY its important. From your example this seems to be all about teachers filling in their timesheets so your scenarios should be things like
Scenario: Fill in timesheet
Given I am a teacher
And I am logged in
When I fill in my timesheet
Then I should see my timesheet has been saved.
You set up state in your Givens, and you build helper methods with each scenario you create, so that future scenarios can set up state easily. For example Given I am a teacher might be something like
def 'Given I am a teacher' do
teacher = create_new_teacher;
register_teacher(teacher)
return teacher
end
Which is building on previous scenarios to register new teachers. If you follow this pattern you can have simple scenarios with a single Given that do vast amounts of setup just using a single method call. This is much better than linking several feature files together!!

Resources