Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Danger] Add some static check rules in dangerfile (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrmswindmill authored and YorkShen committed Jul 23, 2019
1 parent 7e7bec0 commit 0898c8f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
11 changes: 6 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ All PRs should be submitted to master branch -->
<!-- Please follow the template below:
* If you are going to fix a bug of Weex, check whether it already exists in [Github Issue](https://github.com/apache/incubator-weex/issues). If it exists, make sure to write down the link to the corresponding Github issue in the PR you are going to create.
* If you are going to add a feature for weex, reference the following recommend procedure:
1. Writing a email to [mailing list](https://weex.io/guide/contribute/how-to-contribute.html#mailing-list) to talk about what you'd like to do.
1. Write the corresponding [document](https://weex.io/guide/contribute/how-to-contribute.html#contribute-code-or-document) -->
1. Writing a email to [mailing list](https://github.com/apache/incubator-weex/blob/master/CONTRIBUTING.md#mailing-list) to talk about what you'd like to do.
1. Write the corresponding [Documentation](https://github.com/apache/incubator-weex/blob/master/CONTRIBUTING.md#contribute-documentation)
1. Write the corresponding Changelogs at the end of changelog.md -->


# Brief Description of the PR

# Checklist
* [] Demo
* [] Document
* Demo:
* Documentation:

<!-- # Additional content -->
<!-- # Additional content -->
53 changes: 51 additions & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,64 @@
* specific language governing permissions and limitations
* under the License.
*/
import { schedule, danger, fail, warn, message, markdown } from "danger";
// Removed import
import fs from "fs";
import path from 'path';
import GitHubApi from 'github';
import parseDiff from 'parse-diff';

// check if pr submitted to master branch
console.log("checkMasterBranch")
const isMergeRefMaster = danger.github.pr.base.ref === 'master';
if(!isMergeRefMaster){
warn("You'd better to submit PR to master branch as the development of Weex is on master branch.");
}

// match regex line by line
function matchRegex(pr_body,regex){
const lines = pr_body.split("\n");
for (let i = 0; i < lines.length; i++) {
if(lines[i].match(regex)){
return true;
}
}
return false;
}

var pr_body = danger.github.pr.body.toLowerCase();
// Because Pr description template include the following line:
// 1. Write the corresponding [documentation](https://github.com/apache/incubator-weex/blob/master/CONTRIBUTING.md#contribute-code-or-document)
// so we should check the documentation below the ### checklist
console.log("checkDocumentation");
const index = pr_body.indexOf("checklist")
const includeChecklist = (index!=-1)
if(includeChecklist && !matchRegex(pr_body.substring(index),/documentation.*http/)){
const msg = "If you update the code, "+
"maybe you should update the documentation and add the documentation link in the PR description. \n" +
"here is the guide about how to contribute documentation:https://github.com/apache/incubator-weex/blob/master/CONTRIBUTING.md#contribute-code-or-document \n";
warn(msg);
}

// check if pr contains a demo link
console.log("checkDemo");
if(!matchRegex(pr_body,/demo.*http/)){
const msg = "If your PR is about fixing a bug excluding crash the code,"+
"you should add the demo link in the PR description. \n "+
"here is a demo link:http://dotwe.org/vue?spm=a2c7j.-guide-contribute-contribute-code.0.0.3e93748cmxz3yt";
warn(msg);
}

// check if pr bind the github milestone
console.log("checkMileStone");
if(!danger.github.pr.milestone){
warn("Current pr not bind the milestone");
}

// Make sure there are changelog entries
const hasChangelog = danger.git.modified_files.includes("changelog.md")
if (!hasChangelog) { warn("No Changelog changes!") }
if (!hasChangelog) {
warn(`No Changelog changes! - <i>Can you add a Changelog? To do so,append your changes to the changelog.md</i>`);
}

const jsFiles = danger.git.created_files.filter(path => path.endsWith("js"));

Expand Down

0 comments on commit 0898c8f

Please sign in to comment.