From d038e4e3bfa98efb9fc4ed3de377ff13d44ab6cd Mon Sep 17 00:00:00 2001 From: Olga Zinoveva Date: Tue, 4 Apr 2023 15:49:01 -0700 Subject: [PATCH] Add github workflow for automatic API, topic, and component labeling of issues (#36712) Summary: Adding a new github workflow script, which will run as part of the existing triage job that is triggered when an issue is labeled with the "Needs: Triage" label (this typically happens automatically when the issue is created). This script will add an extensive list of possible labels corresponding to APIs, components, and topics (see the code for the full list). The motivation for this change is to replace the last bit of meaningful functionality performed by react-native-bot, which will allow us to decommission that bot in favor of using github workflows for all issue and PR automation. ## Changelog: [INTERNAL] [CHANGED] - Updated API, topic, component labeling on issues to run from a GH workflow rather than an external bot action Pull Request resolved: https://github.com/facebook/react-native/pull/36712 Test Plan: For examples of issues being labeled by this new script, see the open issues here: https://github.com/SlyCaptainFlint/react-native/issues I did not test every possible label, but I tested at least one from each category (API, component, topic), and a combination of one or two of each. Reviewed By: cortinico, cipolleschi Differential Revision: D44593658 Pulled By: SlyCaptainFlint fbshipit-source-id: 93758d05a70d02bed76ab0b6149271e757e0a12f --- .github/workflows/addDescriptiveLabels.js | 153 ++++++++++++++++++++++ .github/workflows/on-issue-labeled.yml | 15 ++- 2 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/addDescriptiveLabels.js 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