2016-11-30 06:56:42 +01:00
## Contributing to the YunoHost core
2016-11-24 02:37:05 +01:00
2016-11-30 06:56:42 +01:00
You wish to add a new feature in the YunoHost core, but don't know how to
proceed? This guide takes you through the various steps of the development and
2016-11-24 02:37:05 +01:00
contribution process.
2016-11-27 04:57:00 +01:00
If you're looking for stuff to implement or fix, the bug-tracker is
2020-07-17 19:21:46 +02:00
[here ](https://github.com/YunoHost/issues/issues )!
2016-11-24 22:23:50 +01:00
2020-07-17 19:21:46 +02:00
**Come say hi to us in the [dev chat room ](/chat_rooms )**!
2016-11-27 04:57:00 +01:00
### Setting up a development environment
2016-11-24 02:37:05 +01:00
- **Use [ynh-dev ](https://github.com/YunoHost/ynh-dev )** (see the README) to
setup a development environment - locally in a virtual machine, or on a VPS.
2016-11-30 06:56:42 +01:00
This will setup a working YunoHost instance, using directly the git repositories
2016-11-27 04:57:00 +01:00
(with symlinks). That way, you will be able to edit files, test your changes in real
time, commit stuff and push/pull directly from your development environment.
2016-11-24 02:37:05 +01:00
2016-11-27 04:57:00 +01:00
- **Implement and test your feature**. Depending on what you want to develop, you
2020-07-17 19:21:46 +02:00
will want to:
- **Python/CLI core**: work in `/ynh-dev/yunohost/`
- **Web administration interface**: work in `/ynh-dev/yunohost-admin/`
2016-11-30 06:56:42 +01:00
- You can also work on the other projects on which YunoHost is built
2020-07-17 19:21:46 +02:00
(SSOwat, Moulinette) in similar ways
2016-11-27 04:57:00 +01:00
2019-10-22 16:39:44 +02:00
### Overview of the 4 main pieces of YunoHost
#### Moulinette
It is a small "homemade" framework. [Its major role ](https://moulinette.readthedocs.io/en/latest/actionsmap.html )
is to allow us to build both a web API and a command-line API from the same
Python code thanks to a YAML schema which we call
[the actionmap ](https://github.com/YunoHost/yunohost/blob/stretch-unstable/data/actionsmap/yunohost.yml ).
It handles other mechanisms like authentication, internationalization and
small technical utilitary functions (e.g. reading/writing json).
Moulinette has its own documentation available [here ](https://moulinette.readthedocs.io/en/latest/ ).
2020-07-17 19:21:46 +02:00
#### YunoHost
2019-10-22 16:39:44 +02:00
This piece is the very core of YunoHost. It contains:
2020-07-17 19:21:46 +02:00
- [the Python code ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/src/yunohost ) that manages users, domains, apps, services and other things
2019-10-22 16:39:44 +02:00
- [bash helpers ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/data/helpers.d ) mainly used by application packagers to package applications
2020-07-17 19:21:46 +02:00
- [hooks ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/data/hooks ) and [templates ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/data/templates ) that are used to configure the various pieces of the ecosystem such as NGINX, Postfix...
2019-10-22 16:39:44 +02:00
- [internationalized strings ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/locales )
- [tests ](https://github.com/YunoHost/yunohost/tree/stretch-unstable/src/yunohost/tests )
#### SSOwat
This is the single sign-on system of YunoHost. It both contains:
2020-07-17 19:21:46 +02:00
- [Lua scripts ](https://github.com/YunoHost/ssowat ) that are directly interfaced with NGINX and handle all the "technical" aspects of authentication and route accesses
2019-10-22 16:39:44 +02:00
- the web [user portal ](https://github.com/YunoHost/SSOwat/tree/stretch-unstable/portal ) which is the interface used by YunoHost's end users to log in and browse installed apps
SSOwat is configured through `/etc/ssowat/conf.json` which is generated by YunoHost.
2020-07-17 19:21:46 +02:00
#### YunoHost-admin
2019-10-22 16:39:44 +02:00
It is an *optional* dependency of YunoHost and corresponds to an interface for the web API created by YunoHost and Moulinette (c.f. the `yunohost-api` service).
It essentially contains:
- [view templates ](https://github.com/YunoHost/yunohost-admin/tree/stretch-unstable/src/views )
2020-07-17 19:21:46 +02:00
- corresponding [javascript controllers ](https://github.com/YunoHost/yunohost-admin/tree/stretch-unstable/src/js/yunohost/controllers ) that interact with the YunoHost API
2019-10-22 16:39:44 +02:00
- and [internationalized strings ](https://github.com/YunoHost/yunohost-admin/tree/stretch-unstable/src/locales )
2016-11-30 06:56:42 +01:00
### Working on the YunoHost Python/CLI core
2016-11-24 02:37:05 +01:00
2019-10-14 17:44:26 +02:00
- Work in `/ynh-dev/yunohost/` .
2016-11-24 02:37:05 +01:00
2019-10-14 17:44:26 +02:00
- Run `cd /ynh_dev/ && ./ynh-dev use-git yunohost` .
2016-11-24 02:37:05 +01:00
- The actionsmap file (`data/actionsmap/yunohost.yml`) defines the various
categories, actions and arguments of the yunohost CLI. Define how you want
users to use your feature, and add/edit the corresponding categories, actions
and arguments. For example in `yunohost domain add some.domain.tld` , the
category is `domain` , the action is `add` , and `some.domain.tld` is an
argument.
2020-07-17 19:21:46 +02:00
- Moulinette will automatically map commands in the actionsmap to Python
2016-11-24 02:37:05 +01:00
functions (and their arguments) located in `src/yunohost/` . For example, typing
`yunohost domain add some.domain.tld` will call the function
`domain_add(domainName)` in `domain.py` , with the argument `domainName` equal
to `"some.domain.tld"` .
2016-11-27 04:57:00 +01:00
##### Helpers / coding style
2016-11-24 02:37:05 +01:00
2019-10-14 17:44:26 +02:00
- To handle exceptions, you should raise some `YunohostError()`
2016-11-24 02:37:05 +01:00
- To help with internationalizing the messages, use `m18n.n('some-message-id')`
and put your string in `locales/en.json` . You can also put arguments and use
them in the string with `{{some-argument:s}}` . Don't edit other locales files,
2016-11-27 04:57:00 +01:00
this will be done using [weblate ](https://translate.yunohost.org/ ) !
2016-11-24 02:37:05 +01:00
2016-11-30 06:56:42 +01:00
- YunoHost tries to follow the [pep8 ](http://pep8.org/ ) coding style. Tools
2016-11-24 02:37:05 +01:00
exist to automatically check conformity.
- Name of "private" functions should start with a `_`
2016-11-30 06:56:42 +01:00
### Working on the YunoHost web administration interface
2016-11-24 02:37:05 +01:00
2019-10-14 17:44:26 +02:00
- Work in `/ynh-dev/yunohost-admin/src/` .
2016-11-24 02:37:05 +01:00
2019-10-14 17:44:26 +02:00
- Run `cd /ynh-dev && ./ynh-dev use-git yunohost-admin` . It launches gulp, such as each
2016-11-24 22:23:50 +01:00
time you modify sources, it recompiles the code and you can use it by
refreshing (Ctrl+F5) your web administration. To stop the command, just do Ctrl+C.
2016-11-30 06:56:42 +01:00
- The web interface uses the API to interact with YunoHost. The API
2016-11-24 02:37:05 +01:00
commands/requests are also defined via the actionsmap. For instance, accessing
2020-07-17 19:21:46 +02:00
the page `https://domain.tld/yunohost/api/users` corresponds to a `GET
2016-11-30 06:56:42 +01:00
/users` requests on the YunoHost API. It is mapped to the function
2016-11-24 02:37:05 +01:00
`user_list()` . Accessing the URL should display the json returned by this
function. 'GET' requests are typically meant to ask information to the server.
'POST' requests are meant to ask the server to edit/change some information,
or to execute some actions.
- `js/yunohost/controllers` contains the javascript parts,
and define which requests to make to the API when loading a specific page of
the interface, and how to process the data to generate the page, using
templates.
- `views` contains the various templates for the pages of the interface. In the
2020-07-17 19:21:46 +02:00
template, data coming from the JavaScript part can be used with the syntax
2016-11-24 02:37:05 +01:00
`{{some-variable}}` , which will be replaced when building/accessing the page.
It is also possible to have conditions using the
2020-07-17 19:21:46 +02:00
[handlebars.js ](http://handlebarsjs.com ) syntax: `{{#if
some-variable}}< p > Some conditional HTML code here !< / p > {{/if}}`
2016-11-24 02:37:05 +01:00
- For internationalized strings, use `y18n.t('some-string-code')` in the
2020-07-17 19:21:46 +02:00
JavaScript, or `{{t 'some-string-code'}}` in the HTML template, and put your
2016-11-27 04:57:00 +01:00
string in `locales/en.json` . Don't edit other locales files,
2020-07-17 19:21:46 +02:00
this will be done using [Weblate ](https://translate.yunohost.org/ )!
2016-11-24 02:37:05 +01:00
2016-11-27 04:57:00 +01:00
##### Don't forget
2016-11-24 02:37:05 +01:00
2020-07-17 19:21:46 +02:00
- Each time you edit the actionsmap or the Python code, you should restart the YunoHost api:
`systemctl restart yunohost-api`
(You'll need to retype your admin and password in the web interface)
2016-11-24 02:37:05 +01:00
2016-11-24 22:23:50 +01:00
- You might need to force-clear the cache of your browser sometimes to refresh
2020-07-17 19:21:46 +02:00
the JavaScript and/or HTML (so each time you edit something in `js` or `views` ).
2016-11-24 02:37:05 +01:00
2016-11-30 06:56:42 +01:00
### Your feature is ready and you want it to be integrated in YunoHost
2016-11-24 02:37:05 +01:00
2020-07-17 19:21:46 +02:00
- Fork the relevant repo on GitHub, and commit stuff to a new branch. We recommend
to name the branch with the following convention:
- For an enhancement or new feature: `enh-ISSUENUMBER-name-of-feature`
2019-10-14 17:44:26 +02:00
- For a bugfix `fix-ISSUENUMBER-description-of-fix`
- `ISSUENUMBER` is optional and is the id of a corresponding ticket on the bug tracker.
2016-11-24 02:37:05 +01:00
2020-07-17 19:21:46 +02:00
- Once you're ready, open a Pull Request (PR) on GitHub. Please include `[fix]` or
2016-11-27 04:57:00 +01:00
`[enh]` at the beginning of the title of your PR.
2016-11-24 02:37:05 +01:00
- After reviewing, testing and validation by other contributors, your branch
2020-07-17 19:21:46 +02:00
should be merged in `unstable` !