Skip to content

Commit

Permalink
Merge pull request #39 from Green-Software-Foundation/refactor-to-pur…
Browse files Browse the repository at this point in the history
…e-functions

Refactor to pure functions
  • Loading branch information
narekhovhannisyan authored Mar 2, 2024
2 parents cccf979 + c2283bf commit 60c528f
Show file tree
Hide file tree
Showing 41 changed files with 2,255 additions and 2,601 deletions.
22 changes: 21 additions & 1 deletion .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,28 @@ module.exports = {
'ci',
'test',
'revert',
'package',
],
],
'scope-enum': [
2,
'always',
[
'util',
'lib',
'types',
'src',
'package',
'config',
'mocks',
'examples',
'.github',
'.husky',
'scripts'
]
],
'scope-empty': [
2,
'never'
]
},
};
13 changes: 6 additions & 7 deletions .github/ISSUE_TEMPLATE/feedback.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Feedback
about: Submiting feedback on the IEF implementation
title: "Feedback - "
about: Submiting feedback on the IF implementation
title: 'Feedback - '
labels: feedback
assignees: ''
---
Expand All @@ -11,17 +11,17 @@ assignees: ''
What does your feedback relate to?

- [] Project aims/objectives
- [] Repository structure
- [] Repository structure
- [] Model plugin
- [] Rimpl code
- [] Rimpl code
- [] Documentation
- [] Tests
- [] Other

## Details

Does your feedback relate to a specific problem that can be demonstrated and reproduced? If so, please provide details of how to repro below.
Include your platform config and the version of IEF you are using (e.g. Ubuntu 20.04, running latest dev branch on XX date).
Include your platform config and the version of IF you are using (e.g. Ubuntu 20.04, running latest dev branch on XX date).

## Expected Behaviour

Expand All @@ -38,5 +38,4 @@ e.g. "issues are sitting on the board for over X days"
What fixes do you propose?
e.g. "please define a response time of X days for issues and publish in the project README"


**Note: We will take all feedback seriously. Please be polite and constructive - aggressive or abusive feedback will simply be deleted.**
**Note: We will take all feedback seriously. Please be polite and constructive - aggressive or abusive feedback will simply be deleted.**
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/user-story.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: User story
about: This describes a user story for IEF
title: "[User story] ...."
about: This describes a user story for IF
title: '[User story] ....'
labels: user-story
assignees: ''

---

As a <type of user> I want <some goal> so that <some reason>.
140 changes: 70 additions & 70 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to if-unofficial-models <!-- omit from toc -->
# Contributing to if-unofficial-plugins <!-- omit from toc -->

First off, thanks for taking the time to contribute! 🎉

Expand All @@ -7,37 +7,37 @@ The following document is a rule set of guidelines for contributing.
## Table of Contents <!-- omit from toc -->

- [Code Contributions](#code-contributions)
- [Step 1: Clone](#step-1-clone)
- [Step 2: Branch](#step-2-branch)
- [Step 3: Commit](#step-3-commit)
- [Step 4: Sync](#step-4-sync)
- [Step 5: Push](#step-5-push)
- [Step 6: Pull Request](#step-6-pull-request)
- [Step 1: Clone](#step-1-clone)
- [Step 2: Branch](#step-2-branch)
- [Step 3: Commit](#step-3-commit)
- [Step 4: Sync](#step-4-sync)
- [Step 5: Push](#step-5-push)
- [Step 6: Pull Request](#step-6-pull-request)
- [Commit message guidelines](#commit-message-guidelines)
- [Coding guidelines](#coding-guidelines)
- [Code structuring patterns](#code-structuring-patterns)
- [Object Oriented Programming](#object-oriented-programming)
- [Functional Programming](#functional-programming)
- [Naming patterns](#naming-patterns)
- [Documentation](#documentation)
- [Writing tests](#writing-tests)
- [Code structuring patterns](#code-structuring-patterns)
- [Object Oriented Programming](#object-oriented-programming)
- [Functional Programming](#functional-programming)
- [Naming patterns](#naming-patterns)
- [Documentation](#documentation)
- [Writing tests](#writing-tests)

## Code Contributions

#### Step 1: Clone

Clone the project on [GitHub]([email protected]:Green-Software-Foundation/if-unofficial-models.git)
```bash
$ git clone [email protected]:Green-Software-Foundation/if-unofficial-models.git
$ cd if-unofficial-models
```
Clone the project on [GitHub]([email protected]:Green-Software-Foundation/if-unofficial-plugins.git)

```bash
$ git clone [email protected]:Green-Software-Foundation/if-unofficial-plugins.git
$ cd if-unofficial-plugins
```

For developing new features and bug fixes, the development branch should be pulled and built upon.

#### Step 2: Branch

Create new branch from main (`staging` or `master`), which will contain your new feature, fix or change.
Create new branch from main (`staging` or `master`), which will contain your new feature, fix or change.

```bash
$ git checkout -b <topic-branch-name>
Expand All @@ -47,43 +47,43 @@ Create new branch from main (`staging` or `master`), which will contain your new

Make sure git knows your name and email address:

```bash
$ git config --global user.name "Example User"
$ git config --global user.email "[email protected]"
```
```bash
$ git config --global user.name "Example User"
$ git config --global user.email "[email protected]"
```

Commiting multiple files with changes on multiple resources is not allowed.
Commit message should clearly describe on which resource changes are made.

Add and commit:

```bash
$ git add my/changed/files
$ git commit
```
```bash
$ git add my/changed/files
$ git commit
```

Commit your changes in logical chunks. Please do not push all changes in one commit.

> Run `npm run fix` before commiting for not having conflict with CI linter.
Please adhere to these [Commit message guidelines](#commit-message-guidelines)
or your code is unlikely be merged into the main project.
or your code is unlikely be merged into the main project.

#### Step 4: Sync

Use git pull/merge to synchronize your work with the main repository.

```bash
$ git pull origin dev
```
```bash
$ git pull origin dev
```

#### Step 5: Push

Push your topic branch:

```bash
$ git push origin <topic-branch-name>
```
```bash
$ git push origin <topic-branch-name>
```

#### Step 6: Pull Request

Expand All @@ -97,40 +97,39 @@ CI included lint checks, running tests, and etc.

The commit message should describe what changed and why.

1. The first line should:
* contain a short description of the change
* be 60 characters or less
* be prefixed with the name of the changed subsystem
* be entirely in lowercase with the exception of proper nouns, acronyms, and the words that refer to code,
like function/variable names

Examples:

```
util: add getInitializedModel method to models.
deps: add express package to dependencies.
service: refactor get user.
```
2. Keep the second line blank.

3. Wrap all other lines at 72 columns:
* describe each line in logical chunks
* start each line with: space hyphen space ( - ...)
* be entirely in lowercase with the exception of proper nouns, acronyms, and the words that refer to code,
like function/variable names

1. The first line should:
- contain a short description of the change
- be 60 characters or less
- be prefixed with the name of the changed subsystem
- be entirely in lowercase with the exception of proper nouns, acronyms, and the words that refer to code,
like function/variable names
Examples:

```
- remove deprecated logger
- refactor some method
- add JSDoc on existing function
```
```
util: add getInitializedModel method to plugins.
deps: add express package to dependencies.
service: refactor get user.
```
2. Keep the second line blank.
3. Wrap all other lines at 72 columns:
- describe each line in logical chunks
- start each line with: space hyphen space ( - ...)
- be entirely in lowercase with the exception of proper nouns, acronyms, and the words that refer to code,
like function/variable names
Examples:
```
- remove deprecated logger
- refactor some method
- add JSDoc on existing function
```
## Coding guidelines
#### Code structuring patterns
Avoid having functions which are responsible to do multiple things at the same time. Make sure one function/method does one thing, and does it well.
Avoid having functions which are responsible to do multiple things at the same time. Make sure one function/method does one thing, and does it well.
###### Object Oriented Programming
Expand Down Expand Up @@ -178,9 +177,10 @@ class MockClass {

#### Writing tests

One test file should be responsible for one module. `describe` blocks should be used for module and function/method description. First `describe` should follow `resource/module: ` pattern. Second describe title should follow `method(): ` pattern. Test units can use either `test` or `it`, title should exactly describe behaviour and input argument. Make sure each test case covers one branch.
One test file should be responsible for one module. `describe` blocks should be used for module and function/method description. First `describe` should follow `resource/module: ` pattern. Second describe title should follow `method(): ` pattern. Test units can use `it`, title should exactly describe behaviour and input argument. Make sure each test case covers one branch.

See example:

See example:
```ts
describe('util/args: ', () => {
describe('parseProcessArgument(): ', () => {
Expand All @@ -191,4 +191,4 @@ describe('util/args: ', () => {
})
```

*[⬅️ back to the root](/README.md#if-unofficial-models)*
_[⬅️ back to the root](/README.md#if-unofficial-plugins)_
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Impact Framework - Unofficial Models

# Impact Framework - Unofficial Plugins

## Implementations

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@grnsft/if-unofficial-models",
"description": "Impact Framework Unofficial Models.",
"version": "v0.1.3",
"name": "@grnsft/if-unofficial-plugins",
"description": "Impact Framework Unofficial Plugins.",
"version": "v0.2.0",
"author": {
"name": "Green Software Foundation",
"email": "[email protected]"
},
"bugs": {
"url": "https://github.com/Green-Software-Foundation/if-unofficial-models/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
"url": "https://github.com/Green-Software-Foundation/if-unofficial-plugins/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
},
"dependencies": {
"@azure/arm-compute": "^21.2.0",
Expand Down Expand Up @@ -53,8 +53,8 @@
"green software",
"green software foundation",
"if",
"if-models",
"models",
"if-plugins",
"plugins",
"unofficial"
],
"license": "MIT",
Expand All @@ -63,7 +63,7 @@
"access": "public"
},
"repository": {
"url": "https://github.com/Green-Software-Foundation/if-unofficial-models.git"
"url": "https://github.com/Green-Software-Foundation/if-unofficial-plugins.git"
},
"scripts": {
"build": "rm -rf build && tsc --project tsconfig.build.json",
Expand All @@ -75,4 +75,4 @@
"prepublish": "npm run build",
"test": "jest --verbose"
}
}
}
10 changes: 5 additions & 5 deletions src/__mocks__/watt-time/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as DATA from './data.json';

export function getMockResponse(url: string, data: any) {
export function getMockResponse(url: string) {
switch (url) {
case 'https://api2.watttime.org/v2/login':
if (
data?.auth?.username === 'test1' &&
data?.auth?.password === 'test2'
process.env.WATT_TIME_USERNAME === 'test1' &&
process.env.WATT_TIME_PASSWORD === 'test2'
) {
return Promise.resolve({
status: 200,
Expand All @@ -21,8 +21,8 @@ export function getMockResponse(url: string, data: any) {

case 'https://apifail.watttime.org/v2/login': {
if (
data?.auth?.username === 'test1' &&
data?.auth?.password === 'test2'
process.env.WATT_TIME_USERNAME === 'test1' &&
process.env.WATT_TIME_PASSWORD === 'test2'
) {
return Promise.resolve({
status: 200,
Expand Down
Loading

0 comments on commit 60c528f

Please sign in to comment.