1 /* gbp-git-pipeline-addin.c
2  *
3  * Copyright 2018-2019 Christian Hergert <chergert@redhat.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * SPDX-License-Identifier: GPL-3.0-or-later
19  */
20 
21 #define G_LOG_DOMAIN "gbp-git-pipeline-addin"
22 
23 #include "config.h"
24 
25 #include <libide-foundry.h>
26 #include <glib/gi18n.h>
27 
28 #include "gbp-git-pipeline-addin.h"
29 #include "gbp-git-submodule-stage.h"
30 #include "gbp-git-vcs.h"
31 
32 struct _GbpGitPipelineAddin
33 {
34   IdeObject parent_instance;
35 };
36 
37 static void
gbp_git_pipeline_addin_load(IdePipelineAddin * addin,IdePipeline * pipeline)38 gbp_git_pipeline_addin_load (IdePipelineAddin *addin,
39                              IdePipeline      *pipeline)
40 {
41   g_autoptr(GbpGitSubmoduleStage) submodule = NULL;
42   IdeContext *context;
43   IdeVcs *vcs;
44   guint stage_id;
45 
46   g_assert (GBP_IS_GIT_PIPELINE_ADDIN (addin));
47   g_assert (IDE_IS_PIPELINE (pipeline));
48 
49   context = ide_object_get_context (IDE_OBJECT (addin));
50   vcs = ide_vcs_from_context (context);
51 
52   /* Ignore everything if this isn't a git-based repository */
53   if (!GBP_IS_GIT_VCS (vcs))
54     return;
55 
56   submodule = gbp_git_submodule_stage_new (context);
57   stage_id = ide_pipeline_attach (pipeline,
58                                   IDE_PIPELINE_PHASE_PREPARE | IDE_PIPELINE_PHASE_AFTER,
59                                   100,
60                                   IDE_PIPELINE_STAGE (submodule));
61   ide_pipeline_addin_track (addin, stage_id);
62 }
63 
64 static void
pipeline_addin_iface_init(IdePipelineAddinInterface * iface)65 pipeline_addin_iface_init (IdePipelineAddinInterface *iface)
66 {
67   iface->load = gbp_git_pipeline_addin_load;
68 }
69 
G_DEFINE_FINAL_TYPE_WITH_CODE(GbpGitPipelineAddin,gbp_git_pipeline_addin,IDE_TYPE_OBJECT,G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN,pipeline_addin_iface_init))70 G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGitPipelineAddin, gbp_git_pipeline_addin, IDE_TYPE_OBJECT,
71                          G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN,
72                                                 pipeline_addin_iface_init))
73 
74 static void
75 gbp_git_pipeline_addin_class_init (GbpGitPipelineAddinClass *klass)
76 {
77 }
78 
79 static void
gbp_git_pipeline_addin_init(GbpGitPipelineAddin * self)80 gbp_git_pipeline_addin_init (GbpGitPipelineAddin *self)
81 {
82 }
83