How can I enable GitHub preview features, like topics? - github-api

I'm using Apps - listRepos to get a list of all the repositories installed on my Probot GitHub application.
I want the response data to include the GitHub topics for each repository. This is currently only available as a preview feature:
The topics property for repositories on GitHub is currently available for developers to preview. To view the topics property in calls that return repository results, you must provide a custom media type in the Accept header:
application/vnd.github.mercy-preview+json
So I think I want to "provide a custom media type in the Accept header".
Is there a way to enable GitHub preview features in Probot? Perhaps by somehow setting RequestOptions?

Success: I added a headers object to my listRepos() call.
const repositories = await octokit.paginate(
octokit.apps.listRepos({
per_page: 100,
headers: {
accept: 'application/vnd.github.machine-man-preview+json,application/vnd.github.mercy-preview+json'
}
}),
res => res.data.repositories // Pull out only the list of repositories from each response.
);

Related

Swagger UI Express with API Versioning

I am using swagger-ui-express and swagger-jsdoc for API Documentation of my node app. The point here is that I have two versions of API in my App and I want to document both of them. I have seen that in .NET Core there is an option available to define the specs and choose one from a dropdown in top bar. I am looking for a similar solution
As a dropdown can be seen in top bar I want similar via swagger-ui-express. Is it possible or if anybody has implemented the same for API Versioning?
Looking forward to your responses.
The solution I propose is not specific to API versioning, but you can have a dropdown of URLs the end-user can choose from. According to the docs, you would need to pass a swaggerOptions object:
const swaggerOptions = {
explorer: true,
swaggerOptions: {
urls: [
{
url: 'https://v1/swagger.json',
name: 'v1'
},
{
url: 'https://v2/swagger.json',
name: 'v2'
}
]
}
}

GitHub API: Number of Stars of a Repository Over Time

Is there a way to retrieve information about the number of stars of a GitHub repository over time? I know I can get a list of all users who starred a repository using the stargazers API endpoint. This doesn't include information about when each user has starred the repo, though. Any hints on how I can retrieve this data?
You can get the property starred_at using this custom media :
Accept: application/vnd.github.v3.star+json
Your headers might look something like this (I'm using Javascript here):
headers: {
...
Accept: 'application/vnd.github.v3.star+json',
...
},
See the documentation here: https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
This repository: https://github.com/timqian/star-history uses this technique to retrieve the stars over time to create a chart.

How to update Google Cloud Platform Legacy GAE and GCF Metadata Server endpoints

I am using firebase cloud functions with Node to send push notifications triggered by realtime database events.
I got this email from Google telling me to update my requests to use the v1 endpoint. The email states:
Our records show that you own projects with App Engine applications or Cloud Functions that are still calling the pre-GA v0.1 and v1beta1 endpoints of the App Engine and Cloud Functions metadata server.
Identify the projects, apps and functions which are making these requests.
Attached to this message you will find the list of projects, applications and functions that you own that have made requests to the v0.1 and v1beta1 metadata server endpoints between Sept 26, 2019 and Nov 1, 2019.
Comment: I know what project it is.
Upgrade your Google client libraries to the latest versions. See supported library versions for the list of Google SDKs that require an update.
Comment: this I don't understand. Do I need to do this?
If you are making direct requests to the legacy Metadata Server endpoints:
To ensure minimal interruption to your instances, please update your requests to the v1 endpoint before April 30, 2020.
Comment: I don't know if I'm making direct requests
How to upgrade from v1beta1 request to v1 requests:
If you are making direct requests to the v1beta1 URI, please follow the following steps to upgrade to the v1 URI:
Change the request URI to use v1 instead of v1beta1
Add this header to your request: “Metadata-Flavor: Google”
For example, if you’re currently making this request:
curl "http://metadata.google.internal/computeMetadata/v1beta1/instance/id"
Upgrade to v1 as follows:
curl "http://metadata.google.internal/computeMetadata/v1/instance/id” -H "Metadata-Flavor: Google"
How to upgrade from v0.1 requests to v1 requests:
If you are making direct requests to the v0.1 URI, please follow the following steps to upgrade to the v1 URI:
Change the request URI to use v1 instead of v0.1
Add this header to your request: “Metadata-Flavor: Google”
Use these instructions to map the v0.1 properties to the v1 properties
For example, if you’re currently making this request:
curl "http://metadata.google.internal/0.1/meta-data/instance-id"
Upgrade to v1 as follows:
curl "http://metadata.google.internal/computeMetadata/v1/instance/id” -H "Metadata-Flavor: Google"
Redeploy your application
The steps above will require another application deployment to take effect.
I searched the Google Cloud support webb (as suggested in the email) and here on SO. But I don’t understand how to do this.
Please bare in mind I’m a complete novice. Any help or advice is greatly appreciated!
UPDATE
Apparently this function has made requests to the v0.1 and v1beta1 metadata server endpoints:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendErrorInputWasSentPush = functions.database.ref('/errorInputs/{barcode}/{date}').onWrite((change, context) => {
const barcode = context.params.barcode
const dataAfter = change.after.val()
const input = dataAfter.input
const pushIDs = [
"",
""]
console.log(`Error input submitted.`)
const payload = {
notification: {
title: '',
body: '',
sound: "default"
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToDevice(pushIDs, payload, options);
});
Firebase versions:
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.2.0"
If you never perform any query to http://metadata.google.internal/... URL from your code or script, that changes nothing!
If you use this URL, paste your code, we could help you.
UPDATE
Thanks to your details, I found the problem in the file src/auth/credential.ts of firebase-admin-node github project. Up to the version 8.1.0 the value of the line 32 is:
const GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1beta1/instance/service-accounts/default/token';
Use the version 8.2.0 or above to solve this

Azure Build Pipeline - Pause and Enable DefinitionQueueStatus change REST API

We have many dozens of build pipelines and we want to pause and resume (re-enable) build pipelines from a simple webapp interface as we are making config changes frequently. Here is the MS doc explaining this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/update%20build?view=azure-devops-rest-5.0#definitionqueuestatus
From this documentation, it appears I need to hit the REST API and change/toggle the DefinitionQueueStatus -- however, this documentation only shows a sample for a build specific operation, whereas I want to pause then re-enable the entire build pipeline. What is the proper way to make this call?
I'm using fetch - and I've tried many dozen formats in the call - the 'ourorg' and 'ourproject' are correct (we use this call structure for many other calls), but all fails for this call below. I grabbed the 'definitionID' from the URL I can visibly see when in the Azure devops portal on the specific build pipeline page, and I'm using it for the {buildID} as I don't know what else to put there. Any guidance to help here is appreciated - I don't need to use fetch btw - any working sample will help here:
fetch(https://dev.azure.com/our_org/our_projectname/_apis/build/builds/definitionId=1593?retry=true&api-version=5.0 {
method: 'PATCH ',
credentials: 'same-origin',
body: 'DefinitionQueueStatus: "Enabled"'
}).then(function(response) {
console.log(response);
})
It seems that the body is incorrect in your post. Here is sample about how to use POSTMAN to access Azure DevOps Services REST APIs.
Generate the PAT, and then record the token, it is important to use to authorization, please see this document.
Create a new request in POSTMAN, it is recommended to put the request in a collection for Azure DevOps Services REST API;
Select the authorization as Basic Auth, you can input the username as any value, and the password as the token which is generated in step1.
Basic Auth
Set the REST API which you want to use,and select the request method type(GET,POST,FETCH ....), here you use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.0.
In the Body tab, you can set the request body as raw in json format, and input the value as following:
{
"buildNumber":"#20190607.2",
"buildNumberRevision":1,
"definition":
{
"id":1,
"createdDate":null,
"queueStatus":"paused"
}
}
Everthing is ready now, you can send the request, if sccuess, you will get the response from the REST API.
In your post, the body content is incorrect, the Request Body should meet the format in the REST API document. The DefinitionQueueStatus is a type in definitions. In addition, if you send the request with parameter retry, you will get the message The request body must be empty when the retry parameter is specified..

Azure Mobile Services Custom API Getting Bad Request on Client

So I'm using azure mobile services backend to try and make a custom API. However I can't seem to connect to even the template table from the client. When you make a new Azure Mobile Service using the template they provide you with this values API controller that resembles this format
[MobileAppController]
public class ValuesController : ApiController
{
// GET api/values
[Route("api/values")]
public string Get()
{
return "test";
}
}
From the client I'm trying to invoke this endpoint like this
var result = mobileService.InvokeApiAsync<string>("values", HttpMethod.Get, null).Result;
And for some reason I keep getting this exception
{"The request could not be completed. (Bad Request)"}
{Method: GET, RequestUri: 'http://localhost:58457/api/values', Version: 1.1, Content: <null>, Headers:
{
X-ZUMO-FEATURES: AT
X-ZUMO-INSTALLATION-ID: b04f4e19-4f41-46ed-9767-9c1352037559
Accept: application/json
User-Agent: ZUMO/1.3
User-Agent: (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0)
X-ZUMO-VERSION: ZUMO/1.3 (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0)
}}
This is only the template too, so I need this to work before I get any of my custom endpoints up and running. Any ideas on what the issue may be?
You can opt out of version checking by setting a value of true for the app setting MS_SkipVersionCheck. Specify this either in your web.config or in the Application Settings section of the Azure Portal.
ms_skipversioncheck to true in the portal.
You say Mobile Service, but the controller you're using is MobileAppController.
This indicates you're actually using Mobile App. If you look in your server project packages.config, you may see something like this.
<package id="Microsoft.Azure.Mobile.Server" version="1.0.119.0" targetFramework="net45" />
I suspect that the 400 you are getting is because you're using a Mobile Client version less than 2.0.0.
In your client project package config, try using a newer client version, such as:
<package id="Microsoft.Azure.Mobile.Client" version="2.0.1" targetFramework="win81" />
You should also inspect the body of the 400 response to get an explicit error message. I expect it to say something like:
{"message":"No API version was specified in the request, this request needs to specify a ZUMO-API-VERSION of '2.0.0'. For more information and supported clients see: http://go.microsoft.com/fwlink/?LinkId=690568#2.0.0"}
I have gone through the below link
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-client-and-server-versioning
which actually says both Mobile Apps client and server SDKs are originally based on those in Mobile Services, but they are not compatible with each other. That is, you must use a Mobile Apps client SDK with a Mobile Apps server SDK and similarly for Mobile Services. This contract is enforced through a special header value used by the client and server SDKs, ZUMO-API-VERSION.
So, you must add Headers in the request
HEADERS: ZUMO-API-VERSION: 2.0.0
Or
http://localhost/api/values/get?ZUMO-API-VERSION=2.0.0
Or
You can opt out of version checking by setting a value of true for the app setting MS_SkipVersionCheck, specify this in your web.config under
Actually even if you specify what version of client you are using in your package.config you will still get the same error of Bad Request. No Zumo version specified. You must pass into your InvokeApiAsync method a parameter specifying the version. For example:
var arguments = new Dictionary<string, string>
{
{"ZUMO-API-VERSION", "2.0.0" }
};
var result = MobileService.InvokeApiAsync<string>("CONTROLLERSNAME", "HttpMethod.Get", arguements).Result;
and bingo it will work.

Resources