Importante
Servicios de terceros y notificaciones push obsoletos
Los servicios de terceros y las notificaciones push en App Services han quedado obsoletos en favor de la creación de puntos finales HTTP que usan dependencias externas en funciones.
Los webhooks se han renombrado como puntos finales HTTPS sin cambios en su comportamiento. Debe migrar los webhooks existentes.
Los servicios existentes continuarán funcionando hasta el de septiembre 30 2025de.
Dado que los servicios de terceros y las notificaciones push ya no se utilizan, se han eliminado de forma predeterminada de la interfaz de usuario de App Services. Si necesita administrar un servicio de terceros o una notificación push existente, puede volver a agregar las configuraciones a la interfaz de usuario siguiendo estos pasos:
En la navegación izquierda, debajo del Manage sección, haga clic en App Settings.
Habilite el interruptor junto a Temporarily Re-Enable 3rd Party Services y luego guarde los cambios.
Overview
Los fragmentos de código de esta página muestran cómo responder a eventos en un repositorio de GitHub a través del Servicio de GitHub. Todos los fragmentos requieren una interfaz del Servicio de GitHub con reglas que permitan las acciones de servicio utilizadas en el fragmento.
Si su aplicación no tiene una interfaz de servicio GitHub, cree una antes de usar estos fragmentos.
Registrar todas las confirmaciones en MongoDB
Esta función de webhook entrante de GitHub registra todas las confirmaciones enviadas a un repositorio en MongoDB en función de un Evento de inserción carga útil de GitHub.
exports = async function(pushEvent) { // Parse the list of commits from the PushEvent payload. // Also grab the user that pushed the commits and the repo information. const { commits, pusher, repository } = pushEvent; // Create a new array of log documents, one for each commit const commitLogs = commits.map(commit => { return { commit: commit, pushed_by: pusher, repo: { name: repository.name, url: repository.url } } }) // Get a client for the `GitHubRepo.logs` collection in MongoDB const mongodb = context.services.get("mongodb-atlas"); const logs = mongodb.db("GitHubRepo").collection("commit-logs"); // Insert the log documents in MongoDB try { const insertResult = await logs.insertMany(commitLogs) console.log(insertResult.insertedIds); } catch(err) { console.error(err) } };
Comentar automáticamente las nuevas solicitudes de extracción
Esta función de webhook entrante de GitHub añade un comentario a las nuevas solicitudes de extracción para agradecer a los usuarios su envío. El webhook acepta una carga útil PullRequestEvent de GitHub y utiliza un cliente de servicio HTTP para crear un comentario a través de la API de GitHub.
exports = async function(pullRequest) { // Get information about the PR from the PullRequestEvent const { action, repository, pull_request: pr } = pullRequest; // Only run if this is a new PR if (action !== "opened") { return } // Construct the GitHub API URL for this PR's Comments const pr_comments_url = { scheme: "https", host: "api.github.com", path: `/repos/${repository.owner.login}/${repository.name}/issues/${pr.number.$numberInt}/comments`, }; // Specify GitHub API Basic Authentication Fields and Headers const github_basic_auth = { username: context.values.get("github-credentials").username, password: context.values.get("github-credentials").password, }; const headers = { // OPTIONAL: Include this header if your security settings require a 2fa code "X-GitHub-OTP": ["<2fa Code>"] }; // Specify the comment text const body = EJSON.stringify({ body: `Thank you for submitting a pull request, ${pr.user.login}!` }); try { // Get an HTTP service client. The service rules should allow you // to send POST requests to `https://api.github.com`. const http = context.services.get("<HTTP Service Name>"); // Send the Request to GitHub const request = { ...github_basic_auth, ...pr_comments_url, headers, body }; const result = await http.post(request); // Check for a Successful Result if (result.statusCode == 201) { return "Successfully commented on the pull request!"; } else { throw new Error(`Received a bad result status from GitHub: ${result.body.text()}`); } } catch (err) { console.error("Something went wrong while posting the comment.", err); } };