Skip to content

Commit

Permalink
Merge branch 'develop' into issue/replacing-dep-constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvv173 authored Aug 1, 2023
2 parents 4441fab + 990dc33 commit bd6f483
Show file tree
Hide file tree
Showing 89 changed files with 5,297 additions and 682 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ version: 2.1
executors:
node-browsers:
docker:
- image: cimg/node:16.20-browsers
- image: cimg/node:18.17-browsers
node-browsers-medium-plus:
docker:
- image: cimg/node:16.20-browsers
- image: cimg/node:18.17-browsers
resource_class: medium+
environment:
NODE_OPTIONS: --max_old_space_size=2048
node-browsers-large:
docker:
- image: cimg/node:16.20-browsers
- image: cimg/node:18.17-browsers
resource_class: large
environment:
NODE_OPTIONS: --max_old_space_size=2048
Expand Down
16 changes: 9 additions & 7 deletions .circleci/scripts/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

PR_NUMBER="${CIRCLE_PULL_REQUEST##*/}"
if [ -n "$PR_NUMBER" ]
IS_NON_FORK_DRAFT='false'

if [[ -n $CIRCLE_PULL_REQUEST ]] && gh auth status
then
IS_DRAFT="$(gh pr view --json isDraft --jq '.isDraft' "$PR_NUMBER")"
else
IS_DRAFT='false'
PR_NUMBER="${CIRCLE_PULL_REQUEST##*/}"
if [ -n "$PR_NUMBER" ]
then
IS_NON_FORK_DRAFT="$(gh pr view --json isDraft --jq '.isDraft' "$PR_NUMBER")"
fi
fi

# Build query to see whether there are any "preview-like" packages in the manifest
Expand All @@ -29,7 +31,7 @@ else
HAS_PREVIEW_BUILDS='false'
fi

if [[ $IS_DRAFT == 'true' && $HAS_PREVIEW_BUILDS == 'true' ]]
if [[ $IS_NON_FORK_DRAFT == 'true' && $HAS_PREVIEW_BUILDS == 'true' ]]
then
# Use GitHub registry on draft PRs, allowing the use of preview builds
echo "Installing with preview builds"
Expand Down
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ module.exports = {
'shared/**/*.test.js',
'ui/**/*.test.js',
'ui/__mocks__/*.js',
'test/e2e/helpers.test.js',
],
extends: ['@metamask/eslint-config-mocha'],
rules: {
Expand All @@ -271,10 +272,12 @@ module.exports = {
'app/scripts/migrations/*.test.js',
'app/scripts/platforms/*.test.js',
'development/**/*.test.js',
'development/**/*.test.ts',
'shared/**/*.test.js',
'shared/**/*.test.ts',
'test/helpers/*.js',
'test/jest/*.js',
'test/e2e/helpers.test.js',
'ui/**/*.test.js',
'ui/__mocks__/*.js',
'shared/lib/error-utils.test.js',
Expand Down
97 changes: 97 additions & 0 deletions .github/scripts/check-pr-has-required-labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as core from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { GitHub } from '@actions/github/lib/utils';

main().catch((error: Error): void => {
console.error(error);
process.exit(1);
});

async function main(): Promise<void> {
// "GITHUB_TOKEN" is an automatically generated, repository-specific access token provided by GitHub Actions.
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
core.setFailed('GITHUB_TOKEN not found');
process.exit(1);
}

// Initialise octokit, required to call Github GraphQL API
const octokit: InstanceType<typeof GitHub> = getOctokit(githubToken);

// Retrieve pull request info from context
const prRepoOwner = context.repo.owner;
const prRepoName = context.repo.repo;
const prNumber = context.payload.pull_request?.number;
if (!prNumber) {
core.setFailed('Pull request number not found');
process.exit(1);
}

// Retrieve pull request labels
const prLabels = await retrievePullRequestLabels(octokit, prRepoOwner, prRepoName, prNumber);

const preventMergeLabels = ["needs-qa", "QA'd but questions", "issues-found", "need-ux-ds-review", "blocked", "stale", "DO-NOT-MERGE"];

let hasTeamLabel = false;

// Check pull request has at least required QA label and team label
for (const label of prLabels) {
if (label.startsWith("team-") || label === "external-contributor") {
console.log(`PR contains a team label as expected: ${label}`);
hasTeamLabel = true;
}
if (preventMergeLabels.includes(label)) {
throw new Error(`PR cannot be merged because it still contains this label: ${label}`);
}
if (hasTeamLabel) {
return;
}
}

// Otherwise, throw an arror to prevent from merging
let errorMessage = '';
if (!hasTeamLabel) {
errorMessage += 'No team labels found on the PR. ';
}
errorMessage += 'Please add the required label(s) before merging the PR.';
throw new Error(errorMessage);

}

// This function retrieves the pull request on a specific repo
async function retrievePullRequestLabels(octokit: InstanceType<typeof GitHub>, repoOwner: string, repoName: string, prNumber: number): Promise<string[]> {

const retrievePullRequestLabelsQuery = `
query RetrievePullRequestLabels($repoOwner: String!, $repoName: String!, $prNumber: Int!) {
repository(owner: $repoOwner, name: $repoName) {
pullRequest(number: $prNumber) {
labels(first: 100) {
nodes {
name
}
}
}
}
}
`;

const retrievePullRequestLabelsResult: {
repository: {
pullRequest: {
labels: {
nodes: {
name: string;
}[];
}
};
};
} = await octokit.graphql(retrievePullRequestLabelsQuery, {
repoOwner,
repoName,
prNumber,
});

const pullRequestLabels = retrievePullRequestLabelsResult?.repository?.pullRequest?.labels?.nodes?.map(labelObject => labelObject?.name);

return pullRequestLabels || [];
}
38 changes: 38 additions & 0 deletions .github/workflows/check-pr-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Check PR has required labels"
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled

jobs:
check-pr-labels:
runs-on: ubuntu-latest
permissions:
pull-requests: read

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # This is needed to checkout all branches

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Install dependencies
run: yarn --immutable

- name: Check PR has required labels
id: check-pr-has-required-labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run check-pr-has-required-labels
17 changes: 0 additions & 17 deletions .github/workflows/do-not-merge.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = {
'./app/scripts/controllers/permissions/**/*.test.js',
'./app/scripts/controllers/mmi-controller.test.js',
'./app/scripts/constants/error-utils.test.js',
'./development/fitness-functions/**/*.test.ts',
'./test/e2e/helpers.test.js',
],
recursive: true,
require: ['test/env.js', 'test/setup.js'],
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ To learn how to contribute to the MetaMask project itself, visit our [Internal D

## Building locally

- Install [Node.js](https://nodejs.org) version 16
- Install [Node.js](https://nodejs.org) version 18
- If you are using [nvm](/~https://github.com/nvm-sh/nvm#installing-and-updating) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
- ONLY follow the steps in the "Install Corepack" and "Updating the global Yarn version" sections
- DO NOT take any of the steps in the "Initializing your project", "Updating to the latest versions" or "Installing the latest build fresh from master" sections. These steps could result in your repo being reset or installing the wrong yarn version, which can break your build.
- ONLY follow the steps in the "Install Corepack" and "Updating the global Yarn version" sections
- DO NOT take any of the steps in the "Initializing your project", "Updating to the latest versions" or "Installing the latest build fresh from master" sections. These steps could result in your repo being reset or installing the wrong yarn version, which can break your build.
- Duplicate `.metamaskrc.dist` within the root and rename it to `.metamaskrc`
- Replace the `INFURA_PROJECT_ID` value with your own personal [Infura Project ID](https://infura.io/docs).
- If debugging MetaMetrics, you'll need to add a value for `SEGMENT_WRITE_KEY` [Segment write key](https://segment.com/docs/connections/find-writekey/), see [Developing on MetaMask - Segment](./development/README.md#segment).
Expand Down
12 changes: 12 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

827 changes: 827 additions & 0 deletions app/images/global-menu-block-explorer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* @file The entry point for the web extension singleton process.
*/

// This import sets up a global function required for Sentry to function.
// It must be run first in case an error is thrown later during initialization.
import './lib/setup-persisted-state-hook';

import EventEmitter from 'events';
import endOfStream from 'end-of-stream';
import pump from 'pump';
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ export default class AppStateController extends EventEmitter {

_acceptApproval() {
if (!this._approvalRequestId) {
log.error('Attempted to accept missing unlock approval request');
return;
}
try {
Expand All @@ -461,7 +460,7 @@ export default class AppStateController extends EventEmitter {
this._approvalRequestId,
);
} catch (error) {
log.error('Failed to accept transaction approval request', error);
log.error('Failed to unlock approval request', error);
}

this._approvalRequestId = null;
Expand Down
49 changes: 0 additions & 49 deletions app/scripts/controllers/app-state.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ObservableStore } from '@metamask/obs-store';
import log from 'loglevel';
import { ORIGIN_METAMASK } from '../../../shared/constants/app';
import AppStateController from './app-state';

jest.mock('loglevel');

let appStateController, mockStore;

describe('AppStateController', () => {
Expand Down Expand Up @@ -147,52 +144,6 @@ describe('AppStateController', () => {
expect.any(String),
);
});

it('logs if rejecting approval request throws', async () => {
appStateController._approvalRequestId = 'mock-approval-request-id';
appStateController = new AppStateController({
addUnlockListener: jest.fn(),
isUnlocked: jest.fn(() => true),
onInactiveTimeout: jest.fn(),
showUnlockRequest: jest.fn(),
preferencesStore: {
subscribe: jest.fn(),
getState: jest.fn(() => ({
preferences: {
autoLockTimeLimit: 0,
},
})),
},
qrHardwareStore: {
subscribe: jest.fn(),
},
messenger: {
call: jest.fn(() => {
throw new Error('mock error');
}),
},
});

appStateController.handleUnlock();

expect(log.error).toHaveBeenCalledTimes(1);
expect(log.error).toHaveBeenCalledWith(
'Attempted to accept missing unlock approval request',
);
});

it('returns without call messenger if no approval request in pending', async () => {
const emitSpy = jest.spyOn(appStateController, 'emit');

appStateController.handleUnlock();

expect(emitSpy).toHaveBeenCalledTimes(0);
expect(appStateController.messagingSystem.call).toHaveBeenCalledTimes(0);
expect(log.error).toHaveBeenCalledTimes(1);
expect(log.error).toHaveBeenCalledWith(
'Attempted to accept missing unlock approval request',
);
});
});

describe('setDefaultHomeActiveTabName', () => {
Expand Down
Loading

0 comments on commit bd6f483

Please sign in to comment.