diff --git a/.github/workflows/addDescriptiveLabels.js b/.github/workflows/addDescriptiveLabels.js new file mode 100644 index 00000000000..547c5fd28e1 --- /dev/null +++ b/.github/workflows/addDescriptiveLabels.js @@ -0,0 +1,153 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +module.exports = async (github, context) => { + const issue = context.payload.issue; + const title = issue?.title?.toLowerCase(); + if (!title) return; + + const addLabels = async labelsToAdd => { + await github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: labelsToAdd, + }); + }; + + const labelsToAdd = []; + for (const component of components) { + if (title.includes(component.toLowerCase())) { + labelsToAdd.push(`Component: ${component}`); + } + } + for (const api of apis) { + if (title.includes(api.toLowerCase())) { + labelsToAdd.push(`API: ${api}`); + } + } + for (const topic of Object.keys(topics)) { + if (title.includes(topic.toLowerCase())) { + labelsToAdd.push(topics[topic]); + } + } + + await addLabels(labelsToAdd); +}; + +const labelAndroid = 'Platform: Android'; +const labelIos = 'Platform: iOS'; +const labelTvos = 'Platform: tvOS'; +const labelNetworking = '🌐Networking'; +const labelBundler = '📦Bundler'; +const labelCli = '💻CLI'; +const labelRegression = 'Impact: Regression'; + +const components = [ + 'ActivityIndicator', + 'Button', + 'DatePickerIOS', + 'DrawerLayoutAndroid', + 'FlatList', + 'Image', + 'ImageBackground', + 'InputAccessoryView', + 'KeyboardAvoidingView', + 'ListView', + 'MaskedViewIOS', + 'Modal', + 'NavigatorIOS', + 'Picker', + 'PickerIOS', + 'ProgressBarAndroid', + 'ProgressViewIOS', + 'RefreshControl', + 'SafeAreaView', + 'ScrollView', + 'SectionList', + 'SegmentedControlIOS', + 'Slider', + 'SnapshotViewIOS', + 'StatusBar', + 'Switch', + 'TabBarIOS', + 'TextInput', + 'ToolbarAndroid', + 'TouchableHighlight', + 'TouchableNativeFeedback', + 'TouchableOpacity', + 'TouchableWithoutFeedback', + 'ViewPagerAndroid', + 'VirtualizedList', + 'WebView', +]; + +const apis = [ + 'AccessibilityInfo', + 'ActionSheetIOS', + 'Alert', + 'AlertIOS', + 'Animated', + 'AppRegistry', + 'AppState', + 'AsyncStorage', + 'BackAndroid', + 'BackHandler', + 'CameraRoll', + 'Clipboard', + 'DatePickerAndroid', + 'Dimensions', + 'Easing', + 'Geolocation', + 'ImageEditor', + 'ImagePickerIOS', + 'ImageStore', + 'InteractionManager', + 'Keyboard', + 'LayoutAnimation', + 'Linking', + 'ListViewDataSource', + 'NetInfo', + 'PanResponder', + 'PermissionsAndroid', + 'PixelRatio', + 'PushNotificationIOS', + 'Settings', + 'Share', + 'StatusBarIOS', + 'StyleSheet', + 'Systrace', + 'TimePickerAndroid', + 'ToastAndroid', + 'Transforms', + 'Vibration', + 'VibrationIOS', +]; + +const topics = { + Flow: 'Flow', + 'Flow-Strict': 'Flow', + xhr: labelNetworking, + netinfo: labelNetworking, + fetch: labelNetworking, + okhttp: labelNetworking, + http: labelNetworking, + bundle: labelBundler, + bundling: labelBundler, + packager: labelBundler, + 'unable to resolve module': labelBundler, + android: labelAndroid, + ios: labelIos, + tvos: labelTvos, + 'react-native-cli': labelCli, + 'react-native upgrade': labelCli, + 'react-native link': labelCli, + 'local-cli': labelCli, + regression: labelRegression, +}; diff --git a/.github/workflows/on-issue-labeled.yml b/.github/workflows/on-issue-labeled.yml index ad74d286cb4..0288573cb33 100644 --- a/.github/workflows/on-issue-labeled.yml +++ b/.github/workflows/on-issue-labeled.yml @@ -15,8 +15,11 @@ jobs: runs-on: ubuntu-latest if: "${{ github.repository == 'facebook/react-native' && contains(github.event.label.name, 'Needs: Triage :mag:') }}" steps: - - uses: actions/checkout@v3 - - uses: actions/github-script@v6 + - name: Checkout code + uses: actions/checkout@v3 + + - name: Verify RN version + uses: actions/github-script@v6 with: script: | const verifyVersion = require('./.github/workflows/verifyVersion.js') @@ -33,6 +36,14 @@ jobs: const actOnLabel = require('./.github/workflows/actOnLabel.js') await actOnLabel(github, context, labelToAdd) } + + - name: Add descriptive label + uses: actions/github-script@v6 + with: + script: | + const addDescriptiveLabel = require('./.github/workflows/addDescriptiveLabels.js') + await addDescriptiveLabel(github, context); + # Reacts to the label that triggered this workflow (added manually or via other workflows) act-on-label: runs-on: ubuntu-latest