Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
{
"extends": "eslint-config-mitodl"
"extends": ["eslint-config-mitodl", "eslint-config-mitodl/flow", "eslint-config-mitodl/mocha"],
"plugins": ["import"],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
// disabled for now to ensure no code changes
"no-unused-vars": "off",
"operator-linebreak": "off",
"react/jsx-no-target-blank": "off"
}
}
4 changes: 4 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
.*/node_modules/react-popper/.*
.*/node_modules/gensync/index.js.flow
.*/node_modules/@webassemblyjs/ieee754/src/index.js
.*/node_modules/@webassemblyjs/helper-numbers/src/index.js
.*/node_modules/html-entities/dist/commonjs/index.js.flow
.*/node_modules/eslint-plugin-flowtype/.*
.*/node_modules/flow-typed/.*
.*.git/.*
.*/staticfiles/.*

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,107 @@
on: [push]
jobs:
python-tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

services:
# Label used to access the service container
db:
# Docker Hub image
image: postgres:12.7
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432

redis:
image: redis:5.0.8
ports:
- 6379:6379

opensearch:
image: opensearchproject/opensearch:1.2.4
env:
network.host: "0.0.0.0"
http.cors.enabled: "true"
http.cors.allow-origin: "*"
rest.action.multi.allow_explicit_index: "false"
ES_JAVA_OPTS: -Xms512m -Xmx512m"
ports:
- 9200:9200

strategy:
matrix:
opensearch-version: [1.2]
steps:
- uses: actions/checkout@v2

- name: Apt install
run: cat Aptfile | sudo xargs apt-get install

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9.1"
python-version: "3.9.24"

- id: cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/test_reqirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: pip install -r requirements.txt -r test_requirements.txt

- name: Lint
run: pylint ./**/*.py

# You must also add the Configure sysctl limits step, otherwise Opensearch will not be able to boot.
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144

- name: Runs Opensearch
uses: ankane/setup-opensearch@v1
# pinned because versions after this drop support for opensearch 1.x
uses: ankane/setup-opensearch@06d8ca27e5805f1d0ad93062c0e947eab2594d64
with:
opensearch-version: ${{ matrix.opensearch-version }}

- name: Tests
run: |
export MEDIA_ROOT="$(mktemp -d)"
sudo mkdir /var/media
sudo chown -R $USER:$USER /var/media
tox
env:
DEBUG: 'False'
NODE_ENV: 'production'
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
MICROMASTERS_SECURE_SSL_REDIRECT: 'False'
MICROMASTERS_DB_DISABLE_SSL: 'True'
OPENSEARCH_URL: localhost:9200
CELERY_TASK_ALWAYS_EAGER: 'True'
BROKER_URL: redis://localhost:6379/4
CELERY_RESULT_BACKEND: redis://localhost:6379/4

- name: Upload coverage to CodeCov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml

javascript-tests:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -109,7 +110,7 @@
- name: Set up NodeJS
uses: actions/setup-node@v2-beta
with:
node-version: "14.18.2"
node-version: "22.20.0"

- name: Set up environment
run: sudo apt-get install libelf1
Expand Down
12 changes: 12 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
require: [
"core-js",
"regenerator-runtime",
"@babel/register"
],
// these need to be here because mocha doesn't provide
// hooks like beforeEach when the file is --require
file: [
"static/js/tests_init.js"
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-bullseye
FROM python:3.9.24
LABEL maintainer "ODL DevOps <[email protected]>"


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-node
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.18.2-bullseye
FROM node:22.20.0-bullseye

LABEL maintainer "ODL DevOps <[email protected]>"

Expand Down
26 changes: 26 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = function(api) {
const isProduction = api.env("production");
const isTest = api.env("test");
return {
presets: isTest ? [
"@babel/env",
"@babel/preset-react"
] : [
["@babel/preset-env", { modules: false }],
"@babel/preset-react",
"@babel/preset-flow"
],
plugins: [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-syntax-dynamic-import",
...(isProduction ? [
"@babel/plugin-transform-react-constant-elements",
"@babel/plugin-transform-react-inline-elements"
] : [
"react-hot-loader/babel"
])
]
};
};
17 changes: 5 additions & 12 deletions courses/mit_learn_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""MIT Learn APIs"""
from urllib.parse import urlencode
from typing import Any, Dict, List

from django.utils.dateparse import parse_datetime
import requests
import re
from typing import Any, Dict, List, Optional

from courses.models import Course, CourseRun
from django.utils.dateparse import parse_datetime
from courses.models import CourseRun


class MITLearnAPIError(Exception):
"""Custom exception for MIT Learn API errors."""
pass


LEARN_API_COURSES_LIST_URL = "https://api.learn.mit.edu/api/v1/courses/"

Expand Down Expand Up @@ -46,12 +46,6 @@ def fetch_course_from_mit_learn(course_id) -> Dict[str, Any]:
return {}








def sync_mit_learn_courseruns_for_course(course, raw_courseruns: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
"""
Process and normalize raw course data from MIT Learn API, but only for courses that already exist in the database.
Expand Down Expand Up @@ -83,4 +77,3 @@ def sync_mit_learn_courseruns_for_course(course, raw_courseruns: List[Dict[str,
num_created += 1
print(f"Created course run: {course_run.edx_course_key} for course {course.title}")
return num_created

11 changes: 6 additions & 5 deletions flow-typed/npm/redux-asserts_v0.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ declare module 'redux-asserts' {
declare type State = any;
declare type StateFunc = ((state: State) => State);

declare type TestStore = {
declare export type ListenForActionsFunc = (actions: Array<string>, () => void) => Promise<State>;
declare export type DispatchThenFunc = (action: Action, expectedActions: Array<string>) => Promise<State>

declare export type TestStore = {
dispatch: Dispatch,
getState: () => State,
subscribe: (listener: () => void) => () => void,
replaceReducer: (reducer: Reducer<any, any>) => void,
createListenForActions: (stateFunc?: StateFunc) => ((actions: Array<string>, () => void) => Promise<State>),
createDispatchThen: (stateFunc?: StateFunc) => (
(action: Action, expectedActions: Array<string>) => Promise<State>
)
createListenForActions: (stateFunc?: StateFunc) => ListenForActionsFunc,
createDispatchThen: (stateFunc?: StateFunc) => DispatchThenFunc
}
declare export default function configureTestStore(reducerFunc?: (state: State) => State): TestStore;
}
86 changes: 45 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@
"type": "git",
"url": "https://github.com/mitodl/micromasters.git"
},
"private": true,
"dependencies": {
"@babel/cli": "^7.28.3",
"@babel/core": "^7.28.4",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-flow-strip-types": "^7.27.1",
"@babel/plugin-transform-react-constant-elements": "^7.27.1",
"@babel/plugin-transform-react-inline-elements": "^7.27.1",
"@babel/plugin-transform-react-jsx": "^7.27.1",
"@babel/preset-env": "^7.28.3",
"@babel/preset-flow": "^7.27.1",
"@babel/preset-react": "^7.27.1",
"@babel/register": "^7.28.3",
"@fancyapps/fancybox": "^3.5.7",
"@material-ui/core": "^4.2.1",
"@mitodl/iso-3166-2": "^1.0.1",
"@sentry/browser": "^6.4.1",
"@sentry/webpack-plugin": "^1.18.3",
"@trust/webcrypto": "^0.9.2",
"@typescript-eslint/eslint-plugin": "^8.46.1",
"ajaxchimp": "^1.3.0",
"autoprefixer": "^7.1.1",
"awesome-phonenumber": "^2.35.0",
"axios-mock-adapter": "^1.8.1",
"babel-core": "^6.24.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^7.0.0",
"babel-plugin-jsx": "^1.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-plugin-transform-react-constant-elements": "^6.9.1",
"babel-plugin-transform-react-inline-elements": "^6.8.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-polyfill": "^6.22.0",
"babel-preset-env": "^1.5.1",
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.24.1",
"babel-loader": "^10.0.0",
"babel-plugin-istanbul": "^7.0.1",
"blueimp-canvas-to-blob": "^3.6.0",
"bootstrap": "^3.3.7",
"casual": "^1.5.17",
Expand All @@ -47,41 +49,46 @@
"diacritics": "^1.3.0",
"draft-js": "^0.10.1",
"draft-js-export-html": "^1.4.1",
"eslint": "7",
"eslint-config-defaults": "9.0.0",
"eslint-config-google": "^0.9.1",
"eslint-config-mitodl": "0.1.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flow-vars": "^0.5.0",
"eslint-plugin-flowtype": "^2.35.1",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-react": "7.1.0",
"eslint-plugin-react-hooks": "4",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^8.x",
"eslint-config-google": "0.14.0",
"eslint-config-mitodl": "^2.1.0",
"eslint-plugin-babel": "5.3.1",
"eslint-plugin-flow-vars": "0.5.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "latest",
"eslint-plugin-mocha": "^10.4.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"express": "^4.15.3",
"fetch-mock": "^5.11.0",
"file-loader": "^0.11.1",
"flow-bin": "^0.43.1",
"flow-typed": "^4.1.1",
"flowgen": "^1.21.0",
"fuse-js-latest": "^2.6.2",
"history": "^4.6.0",
"iflow-lodash": "^1.1.16",
"iflow-react-router": "^1.1.16",
"imports-loader": "^0.7.1",
"isomorphic-fetch": "2.2.1",
"jquery": "^3.5.0",
"jsdom": "^11.0.0",
"jsdom-global": "^3.0.2",
"jsdom": "16.7.0",
"keycode": "^2.1.9",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^1.1.2",
"minimist": "^1.2.8",
"mocha": "8.3.0",
"mocha": "^11.7.4",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"nyc": "^15.0.0",
"object.entries": "^1.0.4",
"postcss-loader": "^2.0.5",
"prettier-eslint-cli": "^5.0.1",
"prettier-eslint": "^16.3.0",
"prettier-eslint-cli": "^8.0.1",
"prop-types": "^15.5.10",
"raf": "^3.4.1",
"ramda": "^0.24.0",
"react": "~16.8",
"react-addons-shallow-compare": "^15.4.0",
Expand Down Expand Up @@ -126,14 +133,14 @@
"url-join": "^2.0.2",
"url-loader": "^0.5.8",
"warning": "^3.0.0",
"webpack": "^4.46.0",
"webpack": "^5.102.1",
"webpack-bundle-tracker": "^0.4.3",
"webpack-cli": "^3.3.10",
"webpack-dev-middleware": "^1.9.0",
"webpack-hot-middleware": "^2.17.1"
"webpack-cli": "^6.0.1",
"webpack-dev-middleware": "latest",
"webpack-hot-middleware": "latest"
},
"engines": {
"node": "14.18.2"
"node": "22.20.0"
},
"scripts": {
"postinstall": "./webpack_if_prod.sh",
Expand All @@ -144,15 +151,12 @@
"codecov": "CODECOV=1 ./scripts/test/js_test.sh",
"watch": "WATCH=1 ./scripts/test/js_test.sh",
"flow": "flow check",
"fmt": "LOG_LEVEL= prettier-eslint --write --no-semi --ignore 'static/js/flow/**/*.js' 'static/js/**/*.js'",
"fmt:check": "prettier-eslint --list-different --no-semi --ignore 'static/js/flow/**/*.js' 'static/js/**/*.js'",
"fmt": "LOG_LEVEL= prettier-eslint --write --no-semi --ignore 'static/js/flow/**' --ignore 'static/js/vendor/**' --ignore 'static/js/data/**' --ignore '*/node_modules/**' 'static/js/**/*.js'",
"fmt:check": "prettier-eslint --list-different --no-semi --ignore 'static/js/flow/**' --ignore 'static/js/vendor/**' --ignore 'static/js/data/**' --ignore '*/node_modules/**' 'static/js/**/*.js'",
"repl": "node --require ./scripts/repl.js"
},
"devDependencies": {
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.2"
},
"resolutions": {
"cheerio": "1.0.0-rc.3",
"merge": "^2.1.1"
},
"packageManager": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.9.1
python-3.9.24
12 changes: 6 additions & 6 deletions scripts/test/js_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ export TMP_FILE=$(mktemp)

if [[ ! -z "$COVERAGE" ]]
then
export CMD="node ./node_modules/nyc/bin/nyc.js --reporter=html mocha"
export CMD="npx nyc --reporter=html mocha"
elif [[ ! -z "$CODECOV" ]]
then
export CMD="node ./node_modules/nyc/bin/nyc.js --reporter=lcovonly -R spec mocha"
export CMD="npx nyc --reporter=lcovonly -R spec mocha"
elif [[ ! -z "$WATCH" ]]
then
export CMD="node ./node_modules/mocha/bin/_mocha --watch"
export CMD="npx mocha --watch"
else
export CMD="node ./node_modules/mocha/bin/_mocha"
export CMD="npx mocha"
fi

export FILE_PATTERN=${1:-'"static/**/*/*_test.js"'}
CMD_ARGS="--require ./static/js/babelhook.js static/js/global_init.js $FILE_PATTERN"
CMD_ARGS="$FILE_PATTERN --exit"

# Second argument (if specified) should be a string that will match specific test case descriptions
#
Expand All @@ -31,7 +31,7 @@ if [[ ! -z "$2" ]]; then
CMD_ARGS+=" -g \"$2\""
fi

eval "$CMD $CMD_ARGS" 2> >(tee "$TMP_FILE")
eval "NODE_ENV=test $CMD $CMD_ARGS" 2> >(tee "$TMP_FILE")

export TEST_RESULT=$?

Expand Down
6 changes: 2 additions & 4 deletions static/js/actions/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ export const addProgramEnrollment = (
dispatch(receiveAddProgramEnrollmentSuccess(enrollment))
dispatch(
setToastMessage({
message: `You are now enrolled in the ${
enrollment.title
} MicroMasters`,
icon: TOAST_SUCCESS
message: `You are now enrolled in the ${enrollment.title} MicroMasters`,
icon: TOAST_SUCCESS
})
)
dispatch(setEnrollProgramDialogVisibility(false))
Expand Down
3 changes: 2 additions & 1 deletion static/js/actions/send_grades_dialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { createAction } from "redux-actions"
import type { Dispatcher } from "../flow/reduxTypes"
import { Dispatch } from "redux"
import type { Dispatch } from "redux"
import { sendGradesRecordMail } from "../lib/api"

export const SET_DIALOG_VISIBILITY = "SET_DIALOG_VISIBILITY"
Expand Down
Loading
Loading