Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the bot work with rst files #300

Open
12rambau opened this issue Apr 16, 2021 · 9 comments · Fixed by #301
Open

make the bot work with rst files #300

12rambau opened this issue Apr 16, 2021 · 9 comments · Fixed by #301

Comments

@12rambau
Copy link
Contributor

12rambau commented Apr 16, 2021

Is your feature request related to a problem? Please describe.
I use the following json file to pilot he all-contributor bot :

{
  "files": [
    "AUTHORS.rst"
  ],
  "imageSize": 100,
  "contributorsPerLine": 7,
  "contributorsSortAlphabetically": false,
  "badgeTemplate":  "<img src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square\" alt=\"All contributors\">",
  "contributorTemplate": "<a href = \"<%= contributor.profile %>\"><img src=\"<%= contributor.avatar_url %>\" width=\"<%= options.imageSize %>px;\" alt=\"\"/><br /><sub><b><%= contributor.name %></b></sub></a>",
  "skipCi": true,
  "contributors": [
    {
      "login": "12rambau",
      "name": "Rambaud Pierrick",
      "avatar_url": "https://avatars.githubusercontent.com/u/12596392?v=4",
      "profile": "https://12rambau.github.io/web-resume/",
      "contributions": [
        "code",
        "ideas",
        "question",
        "doc",
        "maintenance",
        "review"
      ]
    }
  ],
  "projectName": "sepal-doc",
  "projectOwner": "openforis",
  "repoType": "github",
  "repoHost": "https://github.com"
}

and I created the following AUTHOR.rst file to specify the placement of the final table elements :

Thanks goes to these wonderful people (`emoji key <https://allcontributors.org/docs/en/emoji-key>`_):

.. raw:: html
 
    <a href="https://github.com/openforis/sepal-doc/blob/master/AUTHORS.rst">
        <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
        <img src="https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square" alt="All contributors">
        <!-- ALL-CONTRIBUTORS-BADGE:END -->
    </a>

.. raw:: html

    <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
    <!-- prettier-ignore-start -->
    <!-- markdownlint-disable -->
    <table>
    <tr>
       <td align="center"><a href = "https://12rambau.github.io/web-resume/"><img src="https://avatars.githubusercontent.com/u/12596392?v=4" width="100px;" alt=""/><br /><sub><b>Rambaud Pierrick</b></sub></a></td>
    </tr>
    </table>

    <!-- markdownlint-restore -->
    <!-- prettier-ignore-end -->

    <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the `all-contributors <https://allcontributors.org>`_ specification.
Contributions of any kind are welcome!

But when I launch the bot, the indentation change and the file is broken. In short, .rst files are snesible to indentation inside the raw directive and the bot is always rewritting from to very left without identation ending up breaking the rst file.

Describe the solution you'd like
So the problem is indentation, and it would be nothing to change :

in the CLI tools (https://github.com/all-contributors/all-contributors-cli/blob/e9c1f55beb2c18391a5d5f0c9e8243dc3f89ebe3/src/generate/index.js#L7) we parse the text and search for the starting point of the table.
To be working with RST, the code should detect the indentation of this message (<!-- ALL-CONTRIBUTORS-LIST:) and apply it to every line it write afterward. By doing so the .rst users should only right down the "tag" with the correct indentation for the tool to work.

I'm not good at java and I open a SO question on this very matter : https://stackoverflow.com/questions/67069748/how-to-get-the-indent-of-a-searched-item-in-javascript so if anyone can show me ow I think I could make a PR.

Additional context
I don't know if I should post this issue here or in the all-contributor CLI as I don't knwo if the two of them are linked in any way. Feel free to move my issue from here to there if this is more appropriate.

It is the exact same problem (and solution) for the badge.

@Berkmann18 Berkmann18 transferred this issue from all-contributors/app Apr 16, 2021
@Berkmann18
Copy link
Member

I'm aware you may not be good in JavaScript (which I assumed is what you meant instead of Java) so I'm wondering if you have pseudo code / Python implementation of the solution you have in mind (given that you seem to know how to resolve this issue)?
If so, you could write it here and someone could convert it to JS (unless you'll rather do that, even with someone's help).

@12rambau
Copy link
Contributor Author

12rambau commented Apr 19, 2021

So assuming that the variable previousContent is the full extend of the file in 1 single string, I should be able to split it with \n so In python I'll do sometiong like :

# get the indetation of the tag 

tagToLookFor = `<!-- ALL-CONTRIBUTORS-LIST:`

# split the previous content with `\n` character 
split_content = previousContent.split('\n')

for l in split_content:
    if tagToLookFor in l:
        indent = ' '*(len(l) - len(l.lstrip()))
        break

# now i can start every line written by the tool with indent

@12rambau 12rambau mentioned this issue Apr 30, 2021
4 tasks
@12rambau
Copy link
Contributor Author

any news ?

@Berkmann18
Copy link
Member

I saw your PR, I was going to have a proper look but had a lot of things thrown my way and didn't get the chance to do that. I'll try to look into it ASAP.

@12rambau
Copy link
Contributor Author

Thnaks a lot and take your time, I just wanted to make sure that the project was still maintained ;-)

@12rambau
Copy link
Contributor Author

12rambau commented Sep 29, 2022

@tenshiAMD it is still not working, as suggested in #301, I used the bot in one of my repository and the bot deindented the file making it incompatible with .rst

https://github.com/openforis/sepal-doc/pull/230/files

Could you please reopen this issue ?

@tenshiAMD
Copy link
Member

@12rambau looks like there are also issues in configuration and some lines, check my forked repo https://github.com/tenshiAMD/sepal-doc/blob/main/AUTHORS.rst

The only missing here is detecting if the file type is RST then add a tab at beginning of each lines

@tenshiAMD tenshiAMD reopened this Sep 29, 2022
@tenshiAMD tenshiAMD self-assigned this Sep 29, 2022
@12rambau
Copy link
Contributor Author

why not add the tab for all file type? It's harmless for .md and compulsory for .rst

@tenshiAMD
Copy link
Member

tenshiAMD commented Sep 29, 2022

why not add the tab for all file type? It's harmless for .md and compulsory for .rst

@12rambau is not that easy since most of the contents are injected. I think I need to change the implementation somehow. I made a rough fix in this branch and it's working now. I just need to clean things up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants