Last active
May 20, 2022 17:29
-
-
Save EzimetYusup/72bd43a78354c55483f27860d7f70997 to your computer and use it in GitHub Desktop.
Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deployments API example | |
// See: https://developer.github.com/v3/repos/deployments/ to learn more | |
/** | |
* This is the main entrypoint to your Probot app | |
* @param {import('probot').Probot} app | |
*/ | |
const addPRToColumn = async (context, column_id, pr_id) => { | |
const res = await context.octokit.projects.createCard({ | |
column_id: column_id, | |
content_type: 'PullRequest', | |
content_id: pr_id | |
}) | |
app.log.info(res.status); | |
} | |
module.exports = (app) => { | |
// Your code here | |
app.log.info("Yay, the app was loaded!"); | |
app.on( | |
["pull_request.opened", "pull_request.labeled"], | |
async (context) => { | |
// Creates a deployment on a pull request event | |
// Then sets the deployment status to success | |
// NOTE: this example doesn't actually integrate with a cloud | |
// provider to deploy your app, it just demos the basic API usage. | |
// app.log.info(context.payload); | |
// Probot API note: context.repo() => { username: 'hiimbex', repo: 'testing-things' } | |
// await context.octokit.projects.createCard() | |
// await context.octokit.request() | |
app.log.info("heelo2"); | |
const ready_for_review_label = "ready for review"; | |
const labels = context.payload.pull_request.labels; | |
var isReadyForReview = false; | |
labels.forEach(function(label){ | |
if(label.name.toLowerCase().includes(ready_for_review_label)){ | |
isReadyForReview = true; | |
} | |
}) | |
if (!isReadyForReview) { | |
app.log.info("Skipping this PR, since there is no `Ready for review` label"); | |
return; | |
} | |
repo_name = context.payload.repository.name; | |
owner_name = context.payload.repository.owner.login; | |
org = has_org_projects = context.payload.organization; | |
var has_org_projects = false; | |
var project_id = null; | |
const project_prefix = "PR Que".toLowerCase(); | |
const todo_column_name = "To do".toLowerCase(); | |
if(org != null) { | |
has_org_projects = context.payload.organization.has_organization_projects; | |
} | |
if (has_org_projects == true) { | |
// search for the projects at org level | |
const orgPprojects = await context.octokit.projects.listForOrg({ | |
org: org | |
}); | |
orgPprojects.data.forEach(function(pro){ | |
if(pro.name.toLowerCase().includes(project_prefix)){ | |
project_id = pro.id | |
return; | |
} | |
}); | |
} | |
// search for project at repo level | |
const projects = await context.octokit.projects.listForRepo( | |
{ | |
owner:owner_name, | |
repo:repo_name | |
} | |
) | |
projects.data.forEach(function(pro){ | |
app.log.info(`Project Name: ${pro.name}`) | |
if(pro.name.toLowerCase().includes(project_prefix)){ | |
project_id = pro.id | |
} | |
}); | |
if (project_id == null) { | |
app.log.info("Skipping this PR, No valid project board was found to add."); | |
return; | |
} | |
app.log.info(`project_id: ${project_id}`); | |
const list_column_param = { | |
project_id: `${project_id}` | |
} | |
const columns = await context.octokit.projects.listColumns(list_column_param) | |
// app.log.info(columns) | |
var todo_column_id = null; | |
var todo_column = null; | |
columns.data.forEach(function(column){ | |
if (column.name.toLowerCase().includes(todo_column_name)) { | |
todo_column_id = column.id; | |
todo_column = column; | |
return; | |
} | |
}); | |
if (todo_column_id == null) { | |
app.log.info("Skipping this PR, No valid `To Do` column was found in project board."); | |
return; | |
} | |
// app.log.info("comuns:"); | |
// app.log.info(columns); | |
// const COLUMN_ID = 6960108 | |
app.log.info("Adding PR to the TO do list"); | |
const res = await context.octokit.projects.createCard({ | |
column_id: todo_column_id, | |
content_type: 'PullRequest', | |
content_id: context.payload.pull_request.id | |
}) | |
// app.log.info("heelo"); | |
app.log.info(res.status); | |
// context.octokit.repos.proje | |
// const res = await context.octokit.repos.createDeployment( | |
// context.repo({ | |
// ref: context.payload.pull_request.head.ref, // The ref to deploy. This can be a branch, tag, or SHA. | |
// task: "deploy", // Specifies a task to execute (e.g., deploy or deploy:migrations). | |
// auto_merge: true, // Attempts to automatically merge the default branch into the requested ref, if it is behind the default branch. | |
// required_contexts: [], // The status contexts to verify against commit status checks. If this parameter is omitted, then all unique contexts will be verified before a deployment is created. To bypass checking entirely pass an empty array. Defaults to all unique contexts. | |
// payload: { | |
// schema: "rocks!", | |
// }, // JSON payload with extra information about the deployment. Default: "" | |
// environment: "production", // Name for the target deployment environment (e.g., production, staging, qa) | |
// description: "My Probot App's first deploy!", // Short description of the deployment | |
// transient_environment: false, // Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future. | |
// production_environment: true, // Specifies if the given environment is one that end-users directly interact with. | |
// }) | |
// ); | |
// const deploymentId = res.data.id; | |
// await context.octokit.repos.createDeploymentStatus( | |
// context.repo({ | |
// deployment_id: deploymentId, | |
// state: "success", // The state of the status. Can be one of error, failure, inactive, pending, or success | |
// log_url: "https://example.com", // The log URL to associate with this status. This URL should contain output to keep the user updated while the task is running or serve as historical information for what happened in the deployment. | |
// description: "My Probot App set a deployment status!", // A short description of the status. | |
// environment_url: "https://example.com", // Sets the URL for accessing your environment. | |
// auto_inactive: true, // Adds a new inactive status to all prior non-transient, non-production environment deployments with the same repository and environment name as the created status's deployment. An inactive status is only added to deployments that had a success state. | |
// }) | |
// ); | |
} | |
); | |
// For more information on building apps: | |
// https://probot.github.io/docs/ | |
// To get your app running against GitHub, see: | |
// https://probot.github.io/docs/development/ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment