Dangerfile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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: analytics") if @has_analytics_changes
  35. labels.push("api: abtesting") if @has_abtesting_changes
  36. labels.push("api: appcheck") if @has_appcheck_changes
  37. labels.push("api: appdistribution") if @has_appdistribution_changes
  38. labels.push("api: auth") if @has_auth_changes
  39. labels.push("api: core") if @has_core_changes
  40. labels.push("api: crashlytics") if @has_crashlytics_changes
  41. labels.push("api: database") if @has_database_changes
  42. labels.push("api: dynamiclinks") if @has_dynamiclinks_changes
  43. labels.push("api: firestore") if @has_firestore_changes
  44. labels.push("api: functions") if @has_functions_changes
  45. labels.push("api: inappmessaging") if @has_inappmessaging_changes
  46. labels.push("api: installations") if @has_installations_changes
  47. labels.push("api: messaging") if @has_messaging_changes
  48. labels.push("api: performance") if @has_performance_changes
  49. labels.push("api: remoteconfig") if @has_remoteconfig_changes
  50. labels.push("api: storage") if @has_storage_changes
  51. labels.push("release-tooling") if @has_releasetooling_changes
  52. labels.push("public-api-change") if @has_api_changes
  53. return labels
  54. end
  55. ### Definitions
  56. # Label for any change that shouldn't have an accompanying CHANGELOG entry,
  57. # including all changes that do not affect the compiled binary (i.e. script
  58. # changes, test-only changes)
  59. declared_trivial = github.pr_body.include? "#no-changelog"
  60. # Whether or not there are pending changes to any changelog file.
  61. has_changelog_changes = hasChangesIn(["CHANGELOG"])
  62. # Whether or not the LICENSE file has been modified or deleted.
  63. has_license_changes = didModify(["LICENSE"])
  64. ## Product directories
  65. @has_analytics_changes = hasChangesIn([
  66. "FirebaseAnalyticsOnDeviceConversionWrapper",
  67. "FirebaseAnalyticsSwift",
  68. "FirebaseAnalyticsWithoutAdIdSupportWrapper",
  69. "FirebaseAnalyticsWrapper"
  70. ]) || didModify([
  71. "FirebaseAnalytics.podspec.json",
  72. "FirebaseAnalyticsSwift.podspec",
  73. "FirebaseAnalyticsOnDeviceConversion.podspec",
  74. "GoogleAppMeasurement.podspec.json",
  75. "GoogleAppMeasurementOnDeviceConversion.podspec.json"
  76. ])
  77. @has_abtesting_changes = hasChangesIn("FirebaseABTesting")
  78. @has_abtesting_api_changes = hasChangesIn("FirebaseABTesting/Sources/Public/")
  79. @has_appcheck_changes = hasChangesIn("FirebaseAppCheck")
  80. @has_appcheck_api_changes = hasChangesIn("FirebaseAppCheck/Sources/Public/")
  81. @has_appdistribution_changes = hasChangesIn("FirebaseAppDistribution")
  82. @has_appdistribution_api_changes = hasChangesIn("FirebaseAppDistribution/Sources/Public")
  83. @has_auth_changes = hasChangesIn("FirebaseAuth")
  84. @has_auth_api_changes = hasChangesIn("FirebaseAuth/Sources/Public/")
  85. @has_core_changes = hasChangesIn([
  86. "FirebaseCore",
  87. "Firebase/CoreDiagnostics/",
  88. "CoreOnly/"])
  89. @has_core_api_changes = hasChangesIn("FirebaseCore/Sources/Public/")
  90. @has_crashlytics_changes = hasChangesIn("Crashlytics")
  91. @has_crashlytics_api_changes = hasChangesIn("Crashlytics/Crashlytics/Public/")
  92. @has_database_changes = hasChangesIn("FirebaseDatabase")
  93. @has_database_api_changes = hasChangesIn("FirebaseDatabase/Sources/Public/")
  94. @has_dynamiclinks_changes = hasChangesIn("FirebaseDynamicLinks")
  95. @has_dynamiclinks_api_changes = hasChangesIn("FirebaseDynamicLinks/Sources/Public/")
  96. @has_firestore_changes = hasChangesIn(["Firestore/", "FirebaseFirestore.podspec"])
  97. @has_firestore_api_changes = hasChangesIn("Firestore/Source/Public/")
  98. @has_functions_changes = hasChangesIn(["FirebaseFunctions"])
  99. @has_functions_api_changes = hasChangesIn("FirebaseFunctions/Sources/Public/")
  100. @has_inappmessaging_changes = hasChangesIn(["FirebaseInAppMessaging"])
  101. @has_inappmessaging_api_changes = hasChangesIn(["FirebaseInAppMessaging/Sources/Public/"])
  102. @has_installations_changes = hasChangesIn("FirebaseInstallations")
  103. @has_installations_api_changes = hasChangesIn("FirebaseInstallations/Source/Library/Public/")
  104. @has_messaging_changes = hasChangesIn("FirebaseMessaging")
  105. @has_messaging_api_changes = hasChangesIn("FirebaseMessaging/Sources/Public/")
  106. @has_performance_changes = hasChangesIn("FirebasePerformance")
  107. @has_performance_api_changes = hasChangesIn("FirebasePerformance/Sources/Public/")
  108. @has_remoteconfig_changes = hasChangesIn("FirebaseRemoteConfig")
  109. @has_remoteconfig_api_changes = hasChangesIn("FirebaseRemoteConfig/Sources/Public/")
  110. @has_storage_changes = hasChangesIn("FirebaseStorage")
  111. @has_storage_api_changes = hasChangesIn("FirebaseStorageInternal/Sources/Public/")
  112. @has_releasetooling_changes = hasChangesIn("ReleaseTooling/")
  113. # Convenient flag for all API changes.
  114. @has_api_changes = @has_abtesting_api_changes ||
  115. @has_appcheck_api_changes ||
  116. @has_auth_api_changes ||
  117. @has_appdistribution_api_changes ||
  118. @has_core_api_changes ||
  119. @has_crashlytics_api_changes ||
  120. @has_database_api_changes ||
  121. @has_dynamiclinks_api_changes ||
  122. @has_firestore_api_changes ||
  123. @has_functions_api_changes ||
  124. @has_inappmessaging_api_changes ||
  125. @has_installations_api_changes ||
  126. @has_messaging_api_changes ||
  127. @has_performance_api_changes ||
  128. @has_remoteconfig_api_changes ||
  129. @has_storage_api_changes ||
  130. @has_gdt_api_changes
  131. # A FileList containing ObjC, ObjC++ or C++ changes.
  132. sdk_changes = (git.modified_files +
  133. git.added_files +
  134. git.deleted_files).select do |line|
  135. line.end_with?(".h") ||
  136. line.end_with?(".m") ||
  137. line.end_with?(".mm") ||
  138. line.end_with?(".cc") ||
  139. line.end_with?(".swift")
  140. end
  141. # Whether or not the PR has modified SDK source files.
  142. has_sdk_changes = !sdk_changes.empty?
  143. ### Actions
  144. # Warn if a changelog is left out on a non-trivial PR that has modified
  145. # SDK source files (podspec, markdown, etc changes are excluded).
  146. if has_sdk_changes
  147. if !has_changelog_changes && !declared_trivial
  148. warning = "Did you forget to add a changelog entry? (Add #no-changelog"\
  149. " to the PR description to silence this warning.)"
  150. warn(warning)
  151. end
  152. end
  153. # Error on license edits
  154. fail("LICENSE changes are explicitly disallowed.") if has_license_changes
  155. # Label PRs based on diff files
  156. suggested_labels = labelsForModifiedFiles()
  157. if !suggested_labels.empty?
  158. addLabels(suggested_labels)
  159. end