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

Ability to fetch gitlab info (e.g. pipeline status) #231

Closed
agscala opened this issue Apr 2, 2024 · 2 comments · Fixed by #235
Closed

Ability to fetch gitlab info (e.g. pipeline status) #231

agscala opened this issue Apr 2, 2024 · 2 comments · Fixed by #235
Labels
feature request New feature or request

Comments

@agscala
Copy link

agscala commented Apr 2, 2024

Feature Description

I'd like to be able to integrate the pipeline status into my lualine config, but there doesn't seem to be any way to simply return the data.

It would be great if there was an API to give me information about the current MR for use programmatically.

@harrisoncramer harrisoncramer linked a pull request Apr 3, 2024 that will close this issue
@harrisoncramer
Copy link
Owner

harrisoncramer commented Apr 3, 2024

Hello @agscala I've created an MR (see above) that will allow you to query the underlying data behind this plugin. This includes the pipeline data that is used to build the pipeline popup, the currently authenticated user, etc.

The data you're looking for will be available in the response data under data.info.pipeline and can be accessed like this:

  require("gitlab").data({ { type = "info", refresh = true } }, function(data)
    vim.print(data.info.pipeline)
  end)

If you'd like more data please see the gitlab.data() function definition under the help documentation. Please check out this branch of the plugin and let me know how it works for you?

@harrisoncramer harrisoncramer added the feature request New feature or request label Apr 3, 2024
@harrisoncramer
Copy link
Owner

harrisoncramer commented Apr 4, 2024

I've gotten this working for my own Lualine, which I also use, it works like this. In my own personal configuration I have some helpers to tell whether I'm in a Gitlab project and whether I'm looking at a feature branch:

local pipeline_info = ""
local outbound = false
local get_mr_info = {
  function()
    if outbound then
      return pipeline_info
    end
    outbound = true
    require("git-helpers").is_gitlab_project(function()
      require("gitlab").data({ { type = "pipeline", refresh = true } },
        function(data)
          -- At this point you can reference the pipeline information in the callback function
          -- at data.pipeline.latest_pipeline.status, or you can use some of the
          -- utility functions I've added to the pipeline package to make this easier, like the one below:
          pipeline_info = "Gitlab Pipeline: " .. (require("gitlab.actions.pipeline").get_pipeline_icon(true) or "")
          outbound = false
        end)
    end)
    return pipeline_info
  end,
  padding = { left = 0, right = 0 }, -- Adjust padding as needed
}

return {
  'nvim-lualine/lualine.nvim',
  dependencies = { 'nvim-tree/nvim-web-devicons' },
  config = function()
    require("lualine").setup({
      sections = {
        lualine_a = {},
        lualine_b = {},
        lualine_c = { get_mr_info },
      },
    })
  end
}

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

Successfully merging a pull request may close this issue.

2 participants