Arulkumar03/Wheat_HEAD_Detection_Counting_ComputerVision_Model
0
1name: Check issue template2 3on:4 issues:5 types: [opened]6 7jobs:8 check-template:9 runs-on: ubuntu-latest10 # comment this out when testing with https://github.com/nektos/act11 if: ${{ github.repository_owner == 'facebookresearch' }}12 steps:13 - uses: actions/checkout@v214 - uses: actions/github-script@v315 with:16 github-token: ${{secrets.GITHUB_TOKEN}}17 script: |18 // Arguments available:19 // - github: A pre-authenticated octokit/rest.js client20 // - context: An object containing the context of the workflow run21 // - core: A reference to the @actions/core package22 // - io: A reference to the @actions/io package23 const fs = require('fs');24 const editDistance = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/levenshtein.js`).getEditDistance25 issue = await github.issues.get({26 owner: context.issue.owner,27 repo: context.issue.repo,28 issue_number: context.issue.number,29 });30 const hasLabel = issue.data.labels.length > 0;31 if (hasLabel || issue.state === "closed") {32 // don't require template on them33 core.debug("Issue " + issue.data.title + " was skipped.");34 return;35 }36 37 sameAsTemplate = function(filename, body) {38 let tmpl = fs.readFileSync(`.github/ISSUE_TEMPLATE/${filename}`, 'utf8');39 tmpl = tmpl.toLowerCase().split("---").slice(2).join("").trim();40 tmpl = tmpl.replace(/(\r\n|\n|\r)/gm, "");41 let bodyr = body.replace(/(\r\n|\n|\r)/gm, "");42 let dist = editDistance(tmpl, bodyr);43 return dist < 8;44 };45 46 checkFail = async function(msg) {47 core.info("Processing '" + issue.data.title + "' with message: " + msg);48 await github.issues.addLabels({49 owner: context.issue.owner,50 repo: context.issue.repo,51 issue_number: context.issue.number,52 labels: ["needs-more-info"],53 });54 await github.issues.createComment({55 owner: context.issue.owner,56 repo: context.issue.repo,57 issue_number: context.issue.number,58 body: msg,59 });60 };61 62 const body = issue.data.body.toLowerCase().trim();63 64 if (sameAsTemplate("bugs.md", body) || sameAsTemplate("unexpected-problems-bugs.md", body)) {65 await checkFail(`66 We found that not enough information is provided about this issue.67 Please provide details following the [issue template](https://github.com/facebookresearch/detectron2/issues/new/choose).`)68 return;69 }70 71 const hasInstructions = body.indexOf("reproduce") != -1;72 const hasEnvironment = (body.indexOf("environment") != -1) || (body.indexOf("colab") != -1) || (body.indexOf("docker") != -1);73 if (hasInstructions && hasEnvironment) {74 core.debug("Issue " + issue.data.title + " follows template.");75 return;76 }77 78 let message = "You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the [issue template](https://github.com/facebookresearch/detectron2/issues/new/choose).\n";79 message += "The following information is missing: ";80 if (!hasInstructions) {81 message += "\"Instructions To Reproduce the Issue and __Full__ Logs\"; ";82 }83 if (!hasEnvironment) {84 message += "\"Your Environment\"; ";85 }86 await checkFail(message);87 