Dangerfile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ### Helper functions
  2. # Determine if any of the files were changed or deleted.
  3. # Taken from samdmarshall/danger
  4. def didModify(files_array)
  5. files_array.each do |file_name|
  6. if git.modified_files.include?(file_name) ||
  7. git.deleted_files.include?(file_name)
  8. return true
  9. end
  10. end
  11. return false
  12. end
  13. # Determine if there are changes in files matching any of the
  14. # path patterns provided.
  15. def hasChangesIn(paths)
  16. path_array = Array(paths)
  17. path_array.each do |dir|
  18. if !git.modified_files.grep(/#{dir}/).empty?
  19. return true
  20. end
  21. end
  22. return false
  23. end
  24. # Adds the provided labels to the current PR.
  25. def addLabels(label_array)
  26. issue_number = github.pr_json["number"]
  27. repo_name = "firebase/firebase-ios-sdk"
  28. github.api.add_labels_to_an_issue(repo_name, issue_number, label_array)
  29. end
  30. # Returns a list of all labels for a given PR. PRs that touch
  31. # multiple directories may have multiple labels.
  32. def labelsForModifiedFiles()
  33. labels = []
  34. labels.push("api: abtesting") if @has_abtesting_changes
  35. labels.push("api: auth") if @has_auth_changes
  36. labels.push("api: core") if @has_core_changes
  37. labels.push("api: crashlytics") if @has_crashlytics_changes
  38. labels.push("api: database") if @has_database_changes
  39. labels.push("api: dynamiclinks") if @has_dynamiclinks_changes
  40. labels.push("api: firestore") if @has_firestore_changes
  41. labels.push("api: functions") if @has_functions_changes
  42. labels.push("api: inappmessaging") if @has_inappmessaging_changes
  43. labels.push("api: installations") if @has_installations_changes
  44. labels.push("api: instanceid") if @has_instanceid_changes
  45. labels.push("api: messaging") if @has_messaging_changes
  46. labels.push("api: remoteconfig") if @has_remoteconfig_changes
  47. labels.push("api: storage") if @has_storage_changes
  48. labels.push("GoogleDataTransport") if @has_gdt_changes
  49. labels.push("GoogleUtilities") if @has_googleutilities_changes
  50. labels.push("zip-builder") if @has_zipbuilder_changes
  51. return labels
  52. end
  53. ### Definitions
  54. # Label for any change that shouldn't have an accompanying CHANGELOG entry,
  55. # including all changes that do not affect the compiled binary (i.e. script
  56. # changes, test-only changes)
  57. declared_trivial = github.pr_body.include? "#no-changelog"
  58. # Whether or not there are pending changes to any changelog file.
  59. has_changelog_changes = hasChangesIn(["CHANGELOG"])
  60. # Whether or not the LICENSE file has been modified or deleted.
  61. has_license_changes = didModify(["LICENSE"])
  62. ## Product directories
  63. @has_abtesting_changes = hasChangesIn("FirebaseABTesting/")
  64. @has_auth_changes = hasChangesIn("Firebase/Auth")
  65. @has_core_changes = hasChangesIn([
  66. "FirebaseCore/",
  67. "Firebase/CoreDiagnostics/",
  68. "CoreOnly/"])
  69. @has_crashlytics_changes = hasChangesIn("Crashlytics/")
  70. @has_database_changes = hasChangesIn("Firebase/Database/")
  71. @has_dynamiclinks_changes = hasChangesIn("Firebase/DynamicLinks/")
  72. @has_firestore_changes = hasChangesIn("Firestore/")
  73. @has_functions_changes = hasChangesIn("Functions/")
  74. @has_inappmessaging_changes = hasChangesIn(["FirebaseInAppMessaging/"])
  75. @has_installations_changes = hasChangesIn("FirebaseInstallations/Source/")
  76. @has_instanceid_changes = hasChangesIn("Firebase/InstanceID/")
  77. @has_messaging_changes = hasChangesIn("Firebase/Messaging/")
  78. @has_remoteconfig_changes = hasChangesIn("FirebaseRemoteConfig/")
  79. @has_storage_changes = hasChangesIn("FirebaseStorage/")
  80. @has_gdt_changes = hasChangesIn("GoogleDataTransport/") ||
  81. hasChangesIn("GoogleDataTransportCCTSupport")
  82. @has_googleutilities_changes = hasChangesIn("GoogleUtilities/")
  83. @has_zipbuilder_changes = hasChangesIn("ZipBuilder/")
  84. # A FileList containing ObjC, ObjC++ or C++ changes.
  85. sdk_changes = (git.modified_files +
  86. git.added_files +
  87. git.deleted_files).select do |line|
  88. line.end_with?(".h") ||
  89. line.end_with?(".m") ||
  90. line.end_with?(".mm") ||
  91. line.end_with?(".cc") ||
  92. line.end_with?(".swift")
  93. end
  94. # Whether or not the PR has modified SDK source files.
  95. has_sdk_changes = sdk_changes.empty?
  96. ### Actions
  97. # Warn if a changelog is left out on a non-trivial PR that has modified
  98. # SDK source files (podspec, markdown, etc changes are excluded).
  99. if has_sdk_changes
  100. if !has_changelog_changes && !declared_trivial
  101. warning = "Did you forget to add a changelog entry? (Add #no-changelog"\
  102. " to the PR description to silence this warning.)"
  103. warn(warning)
  104. end
  105. end
  106. # Error on license edits
  107. fail("LICENSE changes are explicitly disallowed.") if has_license_changes
  108. # Label PRs based on diff files
  109. suggested_labels = labelsForModifiedFiles()
  110. if !suggested_labels.empty?
  111. addLabels(suggested_labels)
  112. end