You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by so...@apache.org on 2017/03/15 03:23:57 UTC

incubator-weex git commit: 0.11 dev dangerjs (#4)

Repository: incubator-weex
Updated Branches:
  refs/heads/0.11-dev f9b423743 -> 5523afc48


0.11 dev dangerjs (#4)

* [test] use danger.js

Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/5523afc4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/5523afc4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/5523afc4

Branch: refs/heads/0.11-dev
Commit: 5523afc4817bd3ca1e9f57da352d67fd6f9d4c8e
Parents: f9b4237
Author: sospartan zheng <so...@apache.org>
Authored: Wed Mar 15 11:21:18 2017 +0800
Committer: GitHub <no...@github.com>
Committed: Wed Mar 15 11:21:18 2017 +0800

----------------------------------------------------------------------
 .travis.yml                                     |   4 +-
 Dangerfile                                      |  83 -------------
 .../test/java/com/taobao/weex/TestActivity.java |   4 +-
 dangerfile.js                                   | 117 +++++++++++++++++++
 package.json                                    |   8 +-
 test/ci-funcs.sh                                |   4 +-
 6 files changed, 127 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 09416c4..91a1010 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
 os:
   - osx
   - linux
-language: ruby
+language: nodejs
 rvm: 2.0.0
 env:
   - TEST_SUITE=ios
@@ -13,7 +13,7 @@ matrix:
     exclude:
       - os: linux
         env: TEST_SUITE=ios
-      - os: linux
+      - os: osx
         env: TEST_SUITE=danger
       - os: osx
         env: TEST_SUITE=jsfm

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/Dangerfile
----------------------------------------------------------------------
diff --git a/Dangerfile b/Dangerfile
deleted file mode 100644
index 39b4dba..0000000
--- a/Dangerfile
+++ /dev/null
@@ -1,83 +0,0 @@
-# Error or Warn when delete public interface
-metion_break_change = git.commits.any? { |c| c.message =~ /'breack change'/ }
-
-# File name match any of these patterns will be ignored.
-def is_ignored_public_check file
-  ignored_break_change_pattern = Array.[](
-    /^android\/sdk\/src\/test\/.+/,
-    /^android\/playground\/.+/,
-  )
-  for pattern in ignored_break_change_pattern do
-    if file =~ pattern
-      return true
-    end
-  end
-  return false
-end
-
-
-for file in git.modified_files do
-  if not is_ignored_public_check(file) && file.end_with?("java")
-    diff = git.diff_for_file(file)
-    if diff && diff.patch =~ /^-\s*?public\s+[\s\S]+$/ 
-      if metion_break_change
-        warn("Potential BREAK CHANGE. Modify public in #{file}")
-      else
-        warn("Potential BREAK CHANGE. Modify public in #{file} without metion it in commit message. You'd better add 'break change' in your commit log. ")
-      end
-    end
-  end
-end
-
-# Warn when there is a big PR
-warn("Big PR") if git.lines_of_code > 500
-
-has_app_changes = !git.modified_files.grep(/WeexSDK\/Source/).empty?
-has_test_changes = !git.modified_files.grep(/WeexSDKTests/).empty?
-
-# Non-trivial amounts of app changes without tests
-if git.lines_of_code > 100 && has_app_changes && !has_test_changes
-  warn "This PR may need tests."
-end
-
-
-# Fails build when Copyright header is not included
-oc_files = (git.modified_files + git.added_files).uniq.select do |file_path|
-  file_path.end_with?(".h") || file_path.end_with?(".m") || file_path.end_with?(".mm")
-end
-
-copyright_header_components = Array.[](
-  /Created by Weex./,
-  /Copyright \(c\) .*, Alibaba, Inc. All rights reserved./,
-  /This source code is licensed under the Apache Licence 2.0./,
-  /For the full copyright and license information,please view the LICENSE file in the root directory of this source tree./
-)
-
-def has_copyright_header contents, copyright
-  for line in copyright do
-    if not contents =~ line
-      return false
-    end
-  end
-  return true
-end
-
-for file_path in oc_files do
-  contents = File.read(file_path)
-  if not has_copyright_header(contents, copyright_header_components)
-    fail("Objective-C file '#{file_path}' does not have the copyright header.")
-  end
-end
-
-# prose.check_spelling oc_files
-
-# Find reviewers without parsing blame information
-# from files matching to 'Pods/*'
-# mention.run(2, ["Pods/*"], [])
-
-
-# warn("Please add your name", file: "CHANGELOG.md", line: 4)
-
-# fail("Our linter has failed.")
-
-# markdown("## xxxxx")
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/android/sdk/src/test/java/com/taobao/weex/TestActivity.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/TestActivity.java b/android/sdk/src/test/java/com/taobao/weex/TestActivity.java
index f5d2e75..cd82438 100644
--- a/android/sdk/src/test/java/com/taobao/weex/TestActivity.java
+++ b/android/sdk/src/test/java/com/taobao/weex/TestActivity.java
@@ -208,8 +208,8 @@ import android.app.Activity;
 /**
  * Created by sospartan on 7/27/16.
  */
-public  class TestActivity extends Activity {
-  public void test(){
+public   class TestActivity extends Activity {
+  public  void test(){
     //
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/dangerfile.js
----------------------------------------------------------------------
diff --git a/dangerfile.js b/dangerfile.js
new file mode 100644
index 0000000..1dbf20e
--- /dev/null
+++ b/dangerfile.js
@@ -0,0 +1,117 @@
+import { danger, fail, warn } from "danger";
+import fs from "fs";
+
+// Make sure there are changelog entries
+// const hasChangelog = danger.git.modified_files.includes("changelog.md")
+// if (!hasChangelog) { fail("No Changelog changes!") }
+
+const jsFiles = danger.git.created_files.filter(path => path.endsWith("js"));
+
+// new js files should have `@flow` at the top
+const unFlowedFiles = jsFiles.filter(filepath => {
+  const content = fs.readFileSync(filepath);
+  return !content.includes("@flow");
+});
+
+if (unFlowedFiles.length > 0) {
+  warn(
+    `These new JS files do not have Flow enabled: ${unFlowedFiles.join(", ")}`
+  );
+}
+
+// Error or Warn when delete public interface
+var methion_break_change = false;
+for (let c of danger.git.commits) {
+  // console.log("msg:" + c.message);
+  if (c.message && c.message.match(/break\s+change/i)) {
+    methion_break_change = true;
+    break;
+  }
+}
+
+// File name match any of these patterns will be ignored.
+function is_ignored_public_check(file) {
+  var ignored_break_change_pattern = [
+    /^android\/sdk\/src\/test\/.+/,
+     /^android\/playground\/.+/
+  ];
+  for (let p of ignored_break_change_pattern) {
+    if (file.match(p)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+var has_app_changes = false;
+var has_test_changes = false;
+var codefiles = [];
+for (let file of danger.git.modified_files) {
+  console.log("check file:" + file);
+  if (file.match(/WeexSDK\/Source/)) {
+    has_app_changes = true;
+  } else if (file.match(/WeexSDKTests/)) {
+    has_test_changes = true;
+  }
+
+  if (!is_ignored_public_check(file) && file.endsWith(".java")) {
+    var diff = danger.git.diffForFile(file);
+    // console.log("diff\uff1a" + diff+ typeof diff);
+    if (diff && diff.match(/^-\s*?public\s+[\s\S]+$/gm)) {
+      if (methion_break_change) {
+        warn("Potential BREAK CHANGE. Modify public in   " + file);
+      } else {
+        warn(
+          "Potential BREAK CHANGE. Modify public in " +
+            file +
+            " without metion it in commit message. You'd better add 'break change' in your commit log. "
+        );
+      }
+    }
+  }
+
+  if (
+    file.endsWith(".h") ||
+    file.endsWith(".m") ||
+    file.endsWith(".mm")
+  ) {
+    codefiles.push(file);
+  }
+}
+if(danger.git.added_files){
+  for (let file of danger.git.added_files) {
+    if (
+      file.endsWith(".h") ||
+      file.endsWith(".m") ||
+      file.endsWith(".mm")
+    ) {
+      codefiles.push(file);
+    }
+  }
+}
+
+if (danger.git.lines_of_code > 500) {
+  warn("Big PR");
+}
+
+if (danger.git.lines_of_code > 100 && has_app_changes && !has_test_changes) {
+  warn("This PR may need tests.");
+}
+
+//check ios copyright
+const copyright_header_components = [
+  "Created by Weex.",
+  "Copyright \\(c\\) .*, Alibaba, Inc. All rights reserved.",
+  "This source code is licensed under the Apache Licence 2.0.",
+  "For the full copyright and license information,please view the LICENSE file in the root directory of this source tree."
+];
+
+codefiles.forEach(filepath => {
+  const content = fs.readFileSync(filepath).toString();
+  for (const line of copyright_header_components) {
+    if (!content.match(new RegExp(line))) {
+      fail("Code file "+ filepath +" does not have the copyright header.");
+      return;
+    }
+  }
+});

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 39c3f76..69980e8 100644
--- a/package.json
+++ b/package.json
@@ -72,7 +72,8 @@
     "clean": "npm run clean:examples && npm run clean:test",
     "copy:js": "cp -vf ./dist/native.js ./android/sdk/assets/main.js",
     "copy:examples": "rm -rf ./android/playground/app/src/main/assets/* && cp -vrf ./examples/build/* ./android/playground/app/src/main/assets/",
-    "copy": "npm run copy:js && npm run copy:examples"
+    "copy": "npm run copy:js && npm run copy:examples",
+    "danger": "danger"
   },
   "dependencies": {
     "animationjs": "^0.1.5",
@@ -91,9 +92,6 @@
     "weex-styler":"0.1.9"
   },
   "devDependencies": {
-    "xml2map": "^1.0.2",
-    "weex-wd": "^1.0.14",
-    "macaca-utils": "^0.1.9",
     "babel-core": "^6.17.0",
     "babel-istanbul": "^0.11.0",
     "babel-loader": "^6.2.5",
@@ -104,6 +102,7 @@
     "chromedriver": "^2.21.2",
     "cross-spawn": "^4.0.0",
     "css-loader": "^0.26.1",
+    "danger": "^0.11.5",
     "eslint": "^2.11.1",
     "fs-extra": "^2.0.0",
     "http-server": "^0.9.0",
@@ -144,6 +143,7 @@
     "weex-components": "^0.2.0",
     "weex-loader": "^0.4.0",
     "weex-vdom-tester": "^0.2.0",
+    "weex-wd": "^1.0.14",
     "wwp": "^0.3.5",
     "xml2map": "^1.0.2"
   }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5523afc4/test/ci-funcs.sh
----------------------------------------------------------------------
diff --git a/test/ci-funcs.sh b/test/ci-funcs.sh
index 8b4915b..00135fb 100644
--- a/test/ci-funcs.sh
+++ b/test/ci-funcs.sh
@@ -63,7 +63,7 @@ function setup_cpt {
         # setupBasic
         npm install
     else
-        gem install danger danger-xcode_summary xcpretty xcpretty-json-formatter
+        npm install
     fi
 }
 
@@ -111,7 +111,7 @@ function test_cpt {
         npm run build
         npm run test
     else
-        bundle exec danger 
+        npm run danger
     fi
 }